Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #40057 > unrolled thread
| Started by | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| First post | 2021-05-19 13:05 -0700 |
| Last post | 2021-05-20 05:55 -0700 |
| Articles | 19 — 3 participants |
Back to article view | Back to comp.lang.javascript
Serialise setInterval Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-05-19 13:05 -0700
Re: Serialise setInterval Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-05-19 13:42 -0700
Re: Serialise setInterval Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-05-20 03:00 +0100
Re: Serialise setInterval Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-05-20 05:20 -0700
Re: Serialise setInterval Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-05-20 05:22 -0700
Re: Serialise setInterval Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-05-20 05:25 -0700
Re: Serialise setInterval Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-05-20 05:28 -0700
Re: Serialise setInterval Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-05-20 05:36 -0700
Re: Serialise setInterval Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-05-20 05:43 -0700
Re: Serialise setInterval Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-05-20 15:46 +0100
Re: Serialise setInterval Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-05-20 08:13 -0700
Re: Serialise setInterval Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-05-20 16:52 +0100
Re: Serialise setInterval Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-05-20 09:11 -0700
Re: Serialise setInterval Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-05-20 09:17 -0700
Re: Serialise setInterval John G Harris <niam@jghnorth.org.uk.invalid> - 2021-05-20 18:40 +0100
Re: Serialise setInterval Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-05-20 15:31 -0700
Re: Serialise setInterval Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-05-21 15:12 -0700
Re: Serialise setInterval Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-05-21 15:14 -0700
Re: Serialise setInterval Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-05-20 05:55 -0700
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2021-05-19 13:05 -0700 |
| Subject | Serialise setInterval |
| Message-ID | <6b1b8917-b6f8-42bd-bf1a-ac18d7c70624n@googlegroups.com> |
Can someone give a minimalistic example on howto serialise two setIntervals? "To some sort of accuracy"
[toc] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2021-05-19 13:42 -0700 |
| Message-ID | <80fe2283-d42a-4205-bd90-5189e1ed5447n@googlegroups.com> |
| In reply to | #40057 |
onsdag 19 maj 2021 kl. 22:05:19 UTC+2 skrev Jonas Thörnvall:
> Can someone give a minimalistic example on howto serialise two setIntervals?
> "To some sort of accuracy"
Can someone tell why this approach would not work?
function countIn(){
REALTIME=(performance.now()-browserLoadTIME)-2400;
if (REALTIME<0){
stopCount=setInterval(countIn,600);
} else {
clearInterval(stopCount);
stopRec=setInterval(recSomeNotes,5);
}
}
I consider myself logical but i just can't wrap my head around some of the logic within javascript
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2021-05-20 03:00 +0100 |
| Message-ID | <87bl96w4f0.fsf@bsb.me.uk> |
| In reply to | #40058 |
Jonas Thörnvall <jonas.thornvall@gmail.com> writes:
> onsdag 19 maj 2021 kl. 22:05:19 UTC+2 skrev Jonas Thörnvall:
>> Can someone give a minimalistic example on howto serialise two setIntervals?
>> "To some sort of accuracy"
> Can someone tell why this approach would not work?
> function countIn(){
> REALTIME=(performance.now()-browserLoadTIME)-2400;
> if (REALTIME<0){
> stopCount=setInterval(countIn,600);
> } else {
> clearInterval(stopCount);
> stopRec=setInterval(recSomeNotes,5);
> }
> }
This looks very odd. It's possible that you create multiple interval
timers (before you find that REALTIME >= 0), but you only store the ID of
the last one, so all but that one can't be cancelled.
It appears that you want to keep checking some time to take action later
in the else clause. Can't you calculate when REALTIME will become >= 0?
Then you could use setTimeout.
Please learn to use local variables.
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2021-05-20 05:20 -0700 |
| Message-ID | <218df00c-5084-47ae-a2f6-9cb9f8452a83n@googlegroups.com> |
| In reply to | #40059 |
torsdag 20 maj 2021 kl. 04:00:11 UTC+2 skrev Ben Bacarisse:
> Jonas Thörnvall <jonas.t...@gmail.com> writes:
>
> > onsdag 19 maj 2021 kl. 22:05:19 UTC+2 skrev Jonas Thörnvall:
> >> Can someone give a minimalistic example on howto serialise two setIntervals?
> >> "To some sort of accuracy"
> > Can someone tell why this approach would not work?
> > function countIn(){
> > REALTIME=(performance.now()-browserLoadTIME)-2400;
> > if (REALTIME<0){
> > stopCount=setInterval(countIn,600);
> > } else {
> > clearInterval(stopCount);
> > stopRec=setInterval(recSomeNotes,5);
> > }
> > }
> This looks very odd. It's possible that you create multiple interval
> timers (before you find that REALTIME >= 0), but you only store the ID of
> the last one, so all but that one can't be cancelled.
>
> It appears that you want to keep checking some time to take action later
> in the else clause. Can't you calculate when REALTIME will become >= 0?
> Then you could use setTimeout.
>
> Please learn to use local variables.
>
> --
> Ben.
Well that would become 4 timeouts so howto serialise them. The problem with use same setInterval for all is that i have other animation process that also should start at 0 likewise the recording.
I really do not understand how it can be so complex to write two interval function after eachother, it must been anticipated?
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2021-05-20 05:22 -0700 |
| Message-ID | <fc84edc8-fb67-475d-86e2-4b999cfee332n@googlegroups.com> |
| In reply to | #40059 |
torsdag 20 maj 2021 kl. 04:00:11 UTC+2 skrev Ben Bacarisse:
> Jonas Thörnvall <jonas.t...@gmail.com> writes:
>
> > onsdag 19 maj 2021 kl. 22:05:19 UTC+2 skrev Jonas Thörnvall:
> >> Can someone give a minimalistic example on howto serialise two setIntervals?
> >> "To some sort of accuracy"
> > Can someone tell why this approach would not work?
> > function countIn(){
> > REALTIME=(performance.now()-browserLoadTIME)-2400;
> > if (REALTIME<0){
> > stopCount=setInterval(countIn,600);
> > } else {
> > clearInterval(stopCount);
> > stopRec=setInterval(recSomeNotes,5);
> > }
> > }
> This looks very odd. It's possible that you create multiple interval
> timers (before you find that REALTIME >= 0), but you only store the ID of
> the last one, so all but that one can't be cancelled.
>
> It appears that you want to keep checking some time to take action later
> in the else clause. Can't you calculate when REALTIME will become >= 0?
> Then you could use setTimeout.
>
> Please learn to use local variables.
>
> --
> Ben.
Yeah you are correct Ben there seem to be multiple instances created i should break out the call.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2021-05-20 05:25 -0700 |
| Message-ID | <513d1eb1-651c-4624-aef7-8a2ca455ede3n@googlegroups.com> |
| In reply to | #40059 |
torsdag 20 maj 2021 kl. 04:00:11 UTC+2 skrev Ben Bacarisse:
> Jonas Thörnvall <jonas.t...@gmail.com> writes:
>
> > onsdag 19 maj 2021 kl. 22:05:19 UTC+2 skrev Jonas Thörnvall:
> >> Can someone give a minimalistic example on howto serialise two setIntervals?
> >> "To some sort of accuracy"
> > Can someone tell why this approach would not work?
> > function countIn(){
> > REALTIME=(performance.now()-browserLoadTIME)-2400;
> > if (REALTIME<0){
> > stopCount=setInterval(countIn,600);
> > } else {
> > clearInterval(stopCount);
> > stopRec=setInterval(recSomeNotes,5);
> > }
> > }
> This looks very odd. It's possible that you create multiple interval
> timers (before you find that REALTIME >= 0), but you only store the ID of
> the last one, so all but that one can't be cancelled.
>
> It appears that you want to keep checking some time to take action later
> in the else clause. Can't you calculate when REALTIME will become >= 0?
> Then you could use setTimeout.
>
> Please learn to use local variables.
>
> --
> Ben.
I did come up with something like this but it is not working, can anyone see why?
function countIn(){
REALTIME=(performance.now()-browserLoadTIME)-2400;
if (REALTIME<0){
if (mvol==1 || mvol==noteval+1) { metvol=120; } else { metvol=50;}
noteMessage = [153, 77, metvol];
outportarr[outportindex].send(noteMessage);
//DRAWOUT COUNTIN SQUARES
ctT.fillStyle = "red";
ctT.fillRect(240+prog, 5, 10,10);
prog=prog+15;
jint++;
mvol++;
stopCount=setInterval(countIn,600);
} else {
if (rendScroll){
clearInterval(stopCount);
browserLoadTIME=performance.now();
startScrollAnime();
stopRec=setInterval(recSomeNotes,5);
}
}
}
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2021-05-20 05:28 -0700 |
| Message-ID | <53eab967-363f-494a-a9d2-cc08620b670en@googlegroups.com> |
| In reply to | #40066 |
torsdag 20 maj 2021 kl. 14:25:41 UTC+2 skrev Jonas Thörnvall:
> torsdag 20 maj 2021 kl. 04:00:11 UTC+2 skrev Ben Bacarisse:
> > Jonas Thörnvall <jonas.t...@gmail.com> writes:
> >
> > > onsdag 19 maj 2021 kl. 22:05:19 UTC+2 skrev Jonas Thörnvall:
> > >> Can someone give a minimalistic example on howto serialise two setIntervals?
> > >> "To some sort of accuracy"
> > > Can someone tell why this approach would not work?
> > > function countIn(){
> > > REALTIME=(performance.now()-browserLoadTIME)-2400;
> > > if (REALTIME<0){
> > > stopCount=setInterval(countIn,600);
> > > } else {
> > > clearInterval(stopCount);
> > > stopRec=setInterval(recSomeNotes,5);
> > > }
> > > }
> > This looks very odd. It's possible that you create multiple interval
> > timers (before you find that REALTIME >= 0), but you only store the ID of
> > the last one, so all but that one can't be cancelled.
> >
> > It appears that you want to keep checking some time to take action later
> > in the else clause. Can't you calculate when REALTIME will become >= 0?
> > Then you could use setTimeout.
> >
> > Please learn to use local variables.
> >
> > --
> > Ben.
> I did come up with something like this but it is not working, can anyone see why?
> function countIn(){
> REALTIME=(performance.now()-browserLoadTIME)-2400;
> if (REALTIME<0){
> if (mvol==1 || mvol==noteval+1) { metvol=120; } else { metvol=50;}
> noteMessage = [153, 77, metvol];
> outportarr[outportindex].send(noteMessage);
> //DRAWOUT COUNTIN SQUARES
> ctT.fillStyle = "red";
> ctT.fillRect(240+prog, 5, 10,10);
> prog=prog+15;
> jint++;
> mvol++;
> stopCount=setInterval(countIn,600);
> } else {
> if (rendScroll){
> clearInterval(stopCount);
> browserLoadTIME=performance.now();
> startScrollAnime();
> stopRec=setInterval(recSomeNotes,5);
> }
> }
> }
Oops missed this call line outside function.
stopCount=setInterval(countIn,600);
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2021-05-20 05:36 -0700 |
| Message-ID | <720fbe37-8667-47e7-b73f-adc20f555836n@googlegroups.com> |
| In reply to | #40067 |
torsdag 20 maj 2021 kl. 14:28:54 UTC+2 skrev Jonas Thörnvall:
> torsdag 20 maj 2021 kl. 14:25:41 UTC+2 skrev Jonas Thörnvall:
> > torsdag 20 maj 2021 kl. 04:00:11 UTC+2 skrev Ben Bacarisse:
> > > Jonas Thörnvall <jonas.t...@gmail.com> writes:
> > >
> > > > onsdag 19 maj 2021 kl. 22:05:19 UTC+2 skrev Jonas Thörnvall:
> > > >> Can someone give a minimalistic example on howto serialise two setIntervals?
> > > >> "To some sort of accuracy"
> > > > Can someone tell why this approach would not work?
> > > > function countIn(){
> > > > REALTIME=(performance.now()-browserLoadTIME)-2400;
> > > > if (REALTIME<0){
> > > > stopCount=setInterval(countIn,600);
> > > > } else {
> > > > clearInterval(stopCount);
> > > > stopRec=setInterval(recSomeNotes,5);
> > > > }
> > > > }
> > > This looks very odd. It's possible that you create multiple interval
> > > timers (before you find that REALTIME >= 0), but you only store the ID of
> > > the last one, so all but that one can't be cancelled.
> > >
> > > It appears that you want to keep checking some time to take action later
> > > in the else clause. Can't you calculate when REALTIME will become >= 0?
> > > Then you could use setTimeout.
> > >
> > > Please learn to use local variables.
> > >
> > > --
> > > Ben.
> > I did come up with something like this but it is not working, can anyone see why?
> > function countIn(){
> > REALTIME=(performance.now()-browserLoadTIME)-2400;
> > if (REALTIME<0){
> > if (mvol==1 || mvol==noteval+1) { metvol=120; } else { metvol=50;}
> > noteMessage = [153, 77, metvol];
> > outportarr[outportindex].send(noteMessage);
> > //DRAWOUT COUNTIN SQUARES
> > ctT.fillStyle = "red";
> > ctT.fillRect(240+prog, 5, 10,10);
> > prog=prog+15;
> > jint++;
> > mvol++;
> > stopCount=setInterval(countIn,600);
> > } else {
> > if (rendScroll){
> > clearInterval(stopCount);
> > browserLoadTIME=performance.now();
> > startScrollAnime();
> > stopRec=setInterval(recSomeNotes,5);
> > }
> > }
> > }
> Oops missed this call line outside function.
> stopCount=setInterval(countIn,600);
stopCount=setInterval(countIn,600);
function countIn(){
REALTIME=(performance.now()-browserLoadTIME)-2400;
if (REALTIME<0){
if (mvol==1 || mvol==noteval+1) { metvol=120; } else { metvol=50;}
noteMessage = [153, 77, metvol];
outportarr[outportindex].send(noteMessage);
//DRAWOUT COUNTIN SQUARES
ctT.fillStyle = "red";
ctT.fillRect(240+prog, 5, 10,10);
prog=prog+15;
jint++;
mvol++;
stopCount=setInterval(countIn,600);
} else {
if (rendScroll){
startScrollAnime();
}
clearInterval(stopCount);
stopRec=setInterval(recSomeNotes,5);
browserLoadTIME=performance.now();
}
}
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2021-05-20 05:43 -0700 |
| Message-ID | <a4546b64-623c-45a6-8855-d62083e94e7an@googlegroups.com> |
| In reply to | #40069 |
torsdag 20 maj 2021 kl. 14:36:31 UTC+2 skrev Jonas Thörnvall:
> torsdag 20 maj 2021 kl. 14:28:54 UTC+2 skrev Jonas Thörnvall:
> > torsdag 20 maj 2021 kl. 14:25:41 UTC+2 skrev Jonas Thörnvall:
> > > torsdag 20 maj 2021 kl. 04:00:11 UTC+2 skrev Ben Bacarisse:
> > > > Jonas Thörnvall <jonas.t...@gmail.com> writes:
> > > >
> > > > > onsdag 19 maj 2021 kl. 22:05:19 UTC+2 skrev Jonas Thörnvall:
> > > > >> Can someone give a minimalistic example on howto serialise two setIntervals?
> > > > >> "To some sort of accuracy"
> > > > > Can someone tell why this approach would not work?
> > > > > function countIn(){
> > > > > REALTIME=(performance.now()-browserLoadTIME)-2400;
> > > > > if (REALTIME<0){
> > > > > stopCount=setInterval(countIn,600);
> > > > > } else {
> > > > > clearInterval(stopCount);
> > > > > stopRec=setInterval(recSomeNotes,5);
> > > > > }
> > > > > }
> > > > This looks very odd. It's possible that you create multiple interval
> > > > timers (before you find that REALTIME >= 0), but you only store the ID of
> > > > the last one, so all but that one can't be cancelled.
> > > >
> > > > It appears that you want to keep checking some time to take action later
> > > > in the else clause. Can't you calculate when REALTIME will become >= 0?
> > > > Then you could use setTimeout.
> > > >
> > > > Please learn to use local variables.
> > > >
> > > > --
> > > > Ben.
> > > I did come up with something like this but it is not working, can anyone see why?
> > > function countIn(){
> > > REALTIME=(performance.now()-browserLoadTIME)-2400;
> > > if (REALTIME<0){
> > > if (mvol==1 || mvol==noteval+1) { metvol=120; } else { metvol=50;}
> > > noteMessage = [153, 77, metvol];
> > > outportarr[outportindex].send(noteMessage);
> > > //DRAWOUT COUNTIN SQUARES
> > > ctT.fillStyle = "red";
> > > ctT.fillRect(240+prog, 5, 10,10);
> > > prog=prog+15;
> > > jint++;
> > > mvol++;
> > > stopCount=setInterval(countIn,600);
> > > } else {
> > > if (rendScroll){
> > > clearInterval(stopCount);
> > > browserLoadTIME=performance.now();
> > > startScrollAnime();
> > > stopRec=setInterval(recSomeNotes,5);
> > > }
> > > }
> > > }
> > Oops missed this call line outside function.
> > stopCount=setInterval(countIn,600);
> stopCount=setInterval(countIn,600);
> function countIn(){
> REALTIME=(performance.now()-browserLoadTIME)-2400;
> if (REALTIME<0){
> if (mvol==1 || mvol==noteval+1) { metvol=120; } else { metvol=50;}
> noteMessage = [153, 77, metvol];
> outportarr[outportindex].send(noteMessage);
> //DRAWOUT COUNTIN SQUARES
> ctT.fillStyle = "red";
> ctT.fillRect(240+prog, 5, 10,10);
> prog=prog+15;
> jint++;
> mvol++;
> stopCount=setInterval(countIn,600);
> } else {
> if (rendScroll){
> startScrollAnime();
> }
> clearInterval(stopCount);
> stopRec=setInterval(recSomeNotes,5);
> browserLoadTIME=performance.now();
>
> }
> }
A simple example please on howto first run setInterval A and then setInterval B please..... this drives me nuts.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2021-05-20 15:46 +0100 |
| Message-ID | <87a6optqde.fsf@bsb.me.uk> |
| In reply to | #40070 |
Jonas Thörnvall <jonas.thornvall@gmail.com> writes:
> torsdag 20 maj 2021 kl. 14:36:31 UTC+2 skrev Jonas Thörnvall:
>> stopCount=setInterval(countIn,600);
>> function countIn(){
>> REALTIME=(performance.now()-browserLoadTIME)-2400;
>> if (REALTIME<0){
>> if (mvol==1 || mvol==noteval+1) { metvol=120; } else { metvol=50;}
>> noteMessage = [153, 77, metvol];
>> outportarr[outportindex].send(noteMessage);
>> //DRAWOUT COUNTIN SQUARES
>> ctT.fillStyle = "red";
>> ctT.fillRect(240+prog, 5, 10,10);
>> prog=prog+15;
>> jint++;
>> mvol++;
>> stopCount=setInterval(countIn,600);
>> } else {
>> if (rendScroll){
>> startScrollAnime();
>> }
>> clearInterval(stopCount);
>> stopRec=setInterval(recSomeNotes,5);
>> browserLoadTIME=performance.now();
>>
>> }
>> }
I am not going to try to read that. Programmers don't write code like
that for a reason. We've learned not to (by "we" I mean the community
of programmers).
> A simple example please on howto first run setInterval A and then
> setInterval B please..... this drives me nuts.
You can not mean what you say. And if you mean create an interval timer
that fires only once, and then, create a second (which might repeat) then
why are you not using setTimeout for the first?
But to guess a bit at what you want, here is code that waits for two
seconds and then prints "go", after which "tick" is printed five times,
half a second apart.
console.log("Wait for it...");
const longTimer = setInterval(
() => {
clearInterval(longTimer);
console.log("go");
var nTicks = 0;
const shortTimer = setInterval(
() => {
if (nTicks++ >= 5)
clearInterval(shortTimer);
else console.log("tick");
}, 500);
}, 2000);
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2021-05-20 08:13 -0700 |
| Message-ID | <89332481-108f-48d2-8487-fc059757b6een@googlegroups.com> |
| In reply to | #40072 |
torsdag 20 maj 2021 kl. 16:46:29 UTC+2 skrev Ben Bacarisse:
> Jonas Thörnvall <jonas.t...@gmail.com> writes:
>
> > torsdag 20 maj 2021 kl. 14:36:31 UTC+2 skrev Jonas Thörnvall:
>
> >> stopCount=setInterval(countIn,600);
> >> function countIn(){
> >> REALTIME=(performance.now()-browserLoadTIME)-2400;
> >> if (REALTIME<0){
> >> if (mvol==1 || mvol==noteval+1) { metvol=120; } else { metvol=50;}
> >> noteMessage = [153, 77, metvol];
> >> outportarr[outportindex].send(noteMessage);
> >> //DRAWOUT COUNTIN SQUARES
> >> ctT.fillStyle = "red";
> >> ctT.fillRect(240+prog, 5, 10,10);
> >> prog=prog+15;
> >> jint++;
> >> mvol++;
> >> stopCount=setInterval(countIn,600);
> >> } else {
> >> if (rendScroll){
> >> startScrollAnime();
> >> }
> >> clearInterval(stopCount);
> >> stopRec=setInterval(recSomeNotes,5);
> >> browserLoadTIME=performance.now();
> >>
> >> }
> >> }
> I am not going to try to read that. Programmers don't write code like
> that for a reason. We've learned not to (by "we" I mean the community
> of programmers).
> > A simple example please on howto first run setInterval A and then
> > setInterval B please..... this drives me nuts.
> You can not mean what you say. And if you mean create an interval timer
> that fires only once, and then, create a second (which might repeat) then
> why are you not using setTimeout for the first?
>
> But to guess a bit at what you want, here is code that waits for two
> seconds and then prints "go", after which "tick" is printed five times,
> half a second apart.
>
> console.log("Wait for it...");
>
> const longTimer = setInterval(
> () => {
> clearInterval(longTimer);
> console.log("go");
> var nTicks = 0;
> const shortTimer = setInterval(
> () => {
> if (nTicks++ >= 5)
> clearInterval(shortTimer);
> else console.log("tick");
> }, 500);
> }, 2000);
>
> --
> Ben.
Yeah thank you Ben, but where did good ol meta code go. Why does javascript code look so contrieved, two sequentail things nested in eachother LoL, it would be hilarious if it was not deranged.
And things like const longTimer = setInterval( () => { how do one even come up with such concepts and what is it supposed to mean?
Is it setInterval with some sort of inlined function between clause?
And again why is the two intervals calls nested in eachother, is it basicly the same as i do splitting the second call thru the else but you do the second thing inside the first LoL
Can someone honestly say that doing two consecutive processes in this way is not contrieved?
And thanks again Ben, i think i understand the code does not really mean i do.
Do you think we can get a switch on setInterval and setTimeout to run them single threaded......
It would advance the readability of the code with some quadratic factor LoL
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2021-05-20 16:52 +0100 |
| Message-ID | <87zgwps8pw.fsf@bsb.me.uk> |
| In reply to | #40073 |
Jonas Thörnvall <jonas.thornvall@gmail.com> writes:
> torsdag 20 maj 2021 kl. 16:46:29 UTC+2 skrev Ben Bacarisse:
>> console.log("Wait for it...");
>>
>> const longTimer = setInterval(
>> () => {
>> clearInterval(longTimer);
>> console.log("go");
>> var nTicks = 0;
>> const shortTimer = setInterval(
>> () => {
>> if (nTicks++ >= 5)
>> clearInterval(shortTimer);
>> else console.log("tick");
>> }, 500);
>> }, 2000);
My code was indented. Maybe Google broke that as well...
> Yeah thank you Ben, but where did good ol meta code go. Why does
> javascript code look so contrieved, two sequentail things nested in
> eachother LoL, it would be hilarious if it was not deranged.
It's not deranged. It's designed like that for very good reason, but
I'm not going to get into that.
> And things like const longTimer = setInterval( () => { how do one
> even come up with such concepts and what is it supposed to mean?
Which bit? I want a local variable for the returned timer ID. I'm never
going to change it so I'll let everyone know that by declaring it const.
The two things that look like this:
() => { ... code ... }
and simply anonymous functions. They are very similar to functions
sometimes seen in older code created like this
function () { ... code ... }
They are often used for call-backs because you don't usually need to
create a named function when it's going to used in just one place.
> Is it setInterval with some sort of inlined function between clause?
Err... maybe, but inlined doesn't mean what you think it means.
> And again why is the two intervals calls nested in eachother, is it
> basicly the same as i do splitting the second call thru the else but
> you do the second thing inside the first
I don't know what you mean. Here is the same program written with named
functions. Note that I've still decided to limit the scope of the name
of the shortCallback function so it can have exclusive access to the
counter:
console.log("Wait for it...");
const longTimer = setInterval(longCallback, 2000);
function longCallback() {
clearInterval(longTimer);
console.log("go");
var nTicks = 0;
const shortTimer = setInterval(shortCallback, 500);
function shortCallback() {
if (nTicks++ >= 5)
clearInterval(shortTimer);
else console.log("tick");
}
}
> Can someone honestly say that doing two consecutive processes in this
> way is not contrieved?
Yes, there are very good reasons for it.
Unfortunately I'm not convinced that these setTimeout calls are the
right way to do whatever it is you are trying to do.
> And thanks again Ben, i think i understand the code does not really mean i do.
> Do you think we can get a switch on setInterval and setTimeout to run
> them single threaded......
They already run single-threaded.
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2021-05-20 09:11 -0700 |
| Message-ID | <bd697cc9-8ebd-455e-b38f-c6c0362a503fn@googlegroups.com> |
| In reply to | #40074 |
torsdag 20 maj 2021 kl. 17:53:09 UTC+2 skrev Ben Bacarisse:
> Jonas Thörnvall <jonas.t...@gmail.com> writes:
>
> > torsdag 20 maj 2021 kl. 16:46:29 UTC+2 skrev Ben Bacarisse:
> >> console.log("Wait for it...");
> >>
> >> const longTimer = setInterval(
> >> () => {
> >> clearInterval(longTimer);
> >> console.log("go");
> >> var nTicks = 0;
> >> const shortTimer = setInterval(
> >> () => {
> >> if (nTicks++ >= 5)
> >> clearInterval(shortTimer);
> >> else console.log("tick");
> >> }, 500);
> >> }, 2000);
> My code was indented. Maybe Google broke that as well...
> > Yeah thank you Ben, but where did good ol meta code go. Why does
> > javascript code look so contrieved, two sequentail things nested in
> > eachother LoL, it would be hilarious if it was not deranged.
> It's not deranged. It's designed like that for very good reason, but
> I'm not going to get into that.
> > And things like const longTimer = setInterval( () => { how do one
> > even come up with such concepts and what is it supposed to mean?
> Which bit? I want a local variable for the returned timer ID. I'm never
> going to change it so I'll let everyone know that by declaring it const.
>
> The two things that look like this:
>
> () => { ... code ... }
>
> and simply anonymous functions. They are very similar to functions
> sometimes seen in older code created like this
>
> function () { ... code ... }
>
> They are often used for call-backs because you don't usually need to
> create a named function when it's going to used in just one place.
> > Is it setInterval with some sort of inlined function between clause?
> Err... maybe, but inlined doesn't mean what you think it means.
> > And again why is the two intervals calls nested in eachother, is it
> > basicly the same as i do splitting the second call thru the else but
> > you do the second thing inside the first
> I don't know what you mean. Here is the same program written with named
> functions. Note that I've still decided to limit the scope of the name
> of the shortCallback function so it can have exclusive access to the
> counter:
> console.log("Wait for it...");
> const longTimer = setInterval(longCallback, 2000);
>
> function longCallback() {
> clearInterval(longTimer);
> console.log("go");
> var nTicks = 0;
> const shortTimer = setInterval(shortCallback, 500);
>
> function shortCallback() {
> if (nTicks++ >= 5)
> clearInterval(shortTimer);
> else console.log("tick");
> }
> }
> > Can someone honestly say that doing two consecutive processes in this
> > way is not contrieved?
> Yes, there are very good reasons for it.
>
> Unfortunately I'm not convinced that these setTimeout calls are the
> right way to do whatever it is you are trying to do.
> > And thanks again Ben, i think i understand the code does not really mean i do.
> > Do you think we can get a switch on setInterval and setTimeout to run
> > them single threaded......
> They already run single-threaded.
>
> --
> Ben.
Yeah but they run concurrent if you place them in sequense.
setInterval(1)
setInterval(2)
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2021-05-20 09:17 -0700 |
| Message-ID | <d6379de5-e6cb-4063-9202-447a808fbd31n@googlegroups.com> |
| In reply to | #40072 |
torsdag 20 maj 2021 kl. 16:46:29 UTC+2 skrev Ben Bacarisse:
> Jonas Thörnvall <jonas.t...@gmail.com> writes:
>
> > torsdag 20 maj 2021 kl. 14:36:31 UTC+2 skrev Jonas Thörnvall:
>
> >> stopCount=setInterval(countIn,600);
> >> function countIn(){
> >> REALTIME=(performance.now()-browserLoadTIME)-2400;
> >> if (REALTIME<0){
> >> if (mvol==1 || mvol==noteval+1) { metvol=120; } else { metvol=50;}
> >> noteMessage = [153, 77, metvol];
> >> outportarr[outportindex].send(noteMessage);
> >> //DRAWOUT COUNTIN SQUARES
> >> ctT.fillStyle = "red";
> >> ctT.fillRect(240+prog, 5, 10,10);
> >> prog=prog+15;
> >> jint++;
> >> mvol++;
> >> stopCount=setInterval(countIn,600);
> >> } else {
> >> if (rendScroll){
> >> startScrollAnime();
> >> }
> >> clearInterval(stopCount);
> >> stopRec=setInterval(recSomeNotes,5);
> >> browserLoadTIME=performance.now();
> >>
> >> }
> >> }
> I am not going to try to read that. Programmers don't write code like
> that for a reason. We've learned not to (by "we" I mean the community
> of programmers).
> > A simple example please on howto first run setInterval A and then
> > setInterval B please..... this drives me nuts.
> You can not mean what you say. And if you mean create an interval timer
> that fires only once, and then, create a second (which might repeat) then
> why are you not using setTimeout for the first?
>
> But to guess a bit at what you want, here is code that waits for two
> seconds and then prints "go", after which "tick" is printed five times,
> half a second apart.
>
> console.log("Wait for it...");
>
> const longTimer = setInterval(
> () => {
> clearInterval(longTimer);
> console.log("go");
> var nTicks = 0;
> const shortTimer = setInterval(
> () => {
> if (nTicks++ >= 5)
> clearInterval(shortTimer);
> else console.log("tick");
> }, 500);
> }, 2000);
>
> --
> Ben.
A question on a more general topic Ben when one write a programming language "that is parsed" highlevel, do one leave space for add extra parameters for functions?
If so it seem that we could juat add a switch to setTimeout and setInterval, but they probably do not think that long, that there could be extra parameters that simply discarded in the early versions of the parser.
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2021-05-20 18:40 +0100 |
| Message-ID | <ok7dag9hi8ej4avoqmg76fur6vcfil50u6@4ax.com> |
| In reply to | #40076 |
On Thu, 20 May 2021 09:17:37 -0700 (PDT), Jonas Thörnvall <jonas.thornvall@gmail.com> wrote: <snip> >A question on a more general topic Ben when one write a programming language "that is parsed" highlevel, do one leave space for add extra parameters for functions? >If so it seem that we could juat add a switch to setTimeout and setInterval, but they probably do not think that long, that there could be extra parameters that simply discarded in the early versions of the parser. What you need is C++, C#, or Java. (Same name, different number of parameters, makes it a different function.) Perhaps you should review your choice of implementation language. John
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2021-05-20 15:31 -0700 |
| Message-ID | <12f5b6e6-66c6-4587-a483-f5967411fd39n@googlegroups.com> |
| In reply to | #40077 |
torsdag 20 maj 2021 kl. 19:40:51 UTC+2 skrev John G Harris: > On Thu, 20 May 2021 09:17:37 -0700 (PDT), Jonas Thörnvall > <jonas.t...@gmail.com> wrote: > > <snip> > >A question on a more general topic Ben when one write a programming language "that is parsed" highlevel, do one leave space for add extra parameters for functions? > >If so it seem that we could juat add a switch to setTimeout and setInterval, but they probably do not think that long, that there could be extra parameters that simply discarded in the early versions of the parser. > What you need is C++, C#, or Java. (Same name, different number of > parameters, makes it a different function.) Perhaps you should review > your choice of implementation language. > > John No i love the idea of running programs interpreted by the browser, and that is the success story of Javascript, availability.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2021-05-21 15:12 -0700 |
| Message-ID | <640cfe0f-0434-4340-9e2b-d2fa4adea581n@googlegroups.com> |
| In reply to | #40078 |
fredag 21 maj 2021 kl. 00:31:26 UTC+2 skrev Jonas Thörnvall:
> torsdag 20 maj 2021 kl. 19:40:51 UTC+2 skrev John G Harris:
> > On Thu, 20 May 2021 09:17:37 -0700 (PDT), Jonas Thörnvall
> > <jonas.t...@gmail.com> wrote:
> >
> > <snip>
> > >A question on a more general topic Ben when one write a programming language "that is parsed" highlevel, do one leave space for add extra parameters for functions?
> > >If so it seem that we could juat add a switch to setTimeout and setInterval, but they probably do not think that long, that there could be extra parameters that simply discarded in the early versions of the parser.
> > What you need is C++, C#, or Java. (Same name, different number of
> > parameters, makes it a different function.) Perhaps you should review
> > your choice of implementation language.
> >
> > John
> No i love the idea of running programs interpreted by the browser, and that is the success story of Javascript, availability.
Ok now i scrutinised my own code and i can not see why it should not work. I only call recSomeNotes one time after the countIn ended.
And if i skip countIn and go direct one recSomeNotes it work without problem.
First i call countIn 8 times?
The 9 time i stop the countIn
And startup recordSomeNotes "just a single time".
What is wrong i do not get it, it should work?
Because doing this directly work?
stopRec=setInterval(recSomeNotes,5);
So what goes wrong in this code?
stopCount=setInterval(countIn,600);
function countIn(){
if (jint<8){
if (mvol==1 || mvol==noteval+1) { metvol=120; } else { metvol=50;}
noteMessage = [153, 77, metvol];
outportarr[outportindex].send(noteMessage);
ctT.fillStyle = "red";
ctT.fillRect(240+prog, 5, 10,10);
prog=prog+15;
jint++;
mvol++;
} else {
if (rendScroll){
alert("fuck it");
clearInterval(stopCount);
startScrollAnime();
browserLoadTIME=performance.now();
stopRec=setInterval(recSomeNotes,5);
}
}
}
function recSomeNotes(){
REALTIME=performance.now()-browserLoadTIME;
while(REALTIME>schedTime){
outportarr[outportindex].send(noteMessage[playPos]);
if (echo && mode=="Play"){
pianoKeypressOut();
}
schedTime=copyEv[playPos]+schedTime;
playPos++;
}
if (playPos>copyEv.length) {stop();}
}
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2021-05-21 15:14 -0700 |
| Message-ID | <bf0c18cd-2e41-4bee-bb24-7ffe7cb65ad3n@googlegroups.com> |
| In reply to | #40083 |
lördag 22 maj 2021 kl. 00:12:26 UTC+2 skrev Jonas Thörnvall:
> fredag 21 maj 2021 kl. 00:31:26 UTC+2 skrev Jonas Thörnvall:
> > torsdag 20 maj 2021 kl. 19:40:51 UTC+2 skrev John G Harris:
> > > On Thu, 20 May 2021 09:17:37 -0700 (PDT), Jonas Thörnvall
> > > <jonas.t...@gmail.com> wrote:
> > >
> > > <snip>
> > > >A question on a more general topic Ben when one write a programming language "that is parsed" highlevel, do one leave space for add extra parameters for functions?
> > > >If so it seem that we could juat add a switch to setTimeout and setInterval, but they probably do not think that long, that there could be extra parameters that simply discarded in the early versions of the parser.
> > > What you need is C++, C#, or Java. (Same name, different number of
> > > parameters, makes it a different function.) Perhaps you should review
> > > your choice of implementation language.
> > >
> > > John
> > No i love the idea of running programs interpreted by the browser, and that is the success story of Javascript, availability.
> Ok now i scrutinised my own code and i can not see why it should not work. I only call recSomeNotes one time after the countIn ended.
>
> And if i skip countIn and go direct one recSomeNotes it work without problem.
> First i call countIn 8 times?
> The 9 time i stop the countIn
> And startup recordSomeNotes "just a single time".
>
> What is wrong i do not get it, it should work?
> Because doing this directly work?
> stopRec=setInterval(recSomeNotes,5);
>
>
> So what goes wrong in this code?
>
> stopCount=setInterval(countIn,600);
> function countIn(){
> if (jint<8){
> if (mvol==1 || mvol==noteval+1) { metvol=120; } else { metvol=50;}
> noteMessage = [153, 77, metvol];
> outportarr[outportindex].send(noteMessage);
> ctT.fillStyle = "red";
> ctT.fillRect(240+prog, 5, 10,10);
> prog=prog+15;
> jint++;
> mvol++;
> } else {
> if (rendScroll){
> alert("fuck it");
> clearInterval(stopCount);
> startScrollAnime();
> browserLoadTIME=performance.now();
> stopRec=setInterval(recSomeNotes,5);
> }
> }
> }
>
> function recSomeNotes(){
> REALTIME=performance.now()-browserLoadTIME;
> while(REALTIME>schedTime){
> outportarr[outportindex].send(noteMessage[playPos]);
> if (echo && mode=="Play"){
> pianoKeypressOut();
> }
> schedTime=copyEv[playPos]+schedTime;
> playPos++;
> }
> if (playPos>copyEv.length) {stop();}
> }
Oh i get an error message what does it mean?
TypeError: Failed to execute 'send' on 'MIDIOutput': Overload resolution failed.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2021-05-20 05:55 -0700 |
| Message-ID | <f34bee37-def3-4986-a0c2-62a59bc394fdn@googlegroups.com> |
| In reply to | #40069 |
torsdag 20 maj 2021 kl. 14:36:31 UTC+2 skrev Jonas Thörnvall:
> torsdag 20 maj 2021 kl. 14:28:54 UTC+2 skrev Jonas Thörnvall:
> > torsdag 20 maj 2021 kl. 14:25:41 UTC+2 skrev Jonas Thörnvall:
> > > torsdag 20 maj 2021 kl. 04:00:11 UTC+2 skrev Ben Bacarisse:
> > > > Jonas Thörnvall <jonas.t...@gmail.com> writes:
> > > >
> > > > > onsdag 19 maj 2021 kl. 22:05:19 UTC+2 skrev Jonas Thörnvall:
> > > > >> Can someone give a minimalistic example on howto serialise two setIntervals?
> > > > >> "To some sort of accuracy"
> > > > > Can someone tell why this approach would not work?
> > > > > function countIn(){
> > > > > REALTIME=(performance.now()-browserLoadTIME)-2400;
> > > > > if (REALTIME<0){
> > > > > stopCount=setInterval(countIn,600);
> > > > > } else {
> > > > > clearInterval(stopCount);
> > > > > stopRec=setInterval(recSomeNotes,5);
> > > > > }
> > > > > }
> > > > This looks very odd. It's possible that you create multiple interval
> > > > timers (before you find that REALTIME >= 0), but you only store the ID of
> > > > the last one, so all but that one can't be cancelled.
> > > >
> > > > It appears that you want to keep checking some time to take action later
> > > > in the else clause. Can't you calculate when REALTIME will become >= 0?
> > > > Then you could use setTimeout.
> > > >
> > > > Please learn to use local variables.
> > > >
> > > > --
> > > > Ben.
> > > I did come up with something like this but it is not working, can anyone see why?
> > > function countIn(){
> > > REALTIME=(performance.now()-browserLoadTIME)-2400;
> > > if (REALTIME<0){
> > > if (mvol==1 || mvol==noteval+1) { metvol=120; } else { metvol=50;}
> > > noteMessage = [153, 77, metvol];
> > > outportarr[outportindex].send(noteMessage);
> > > //DRAWOUT COUNTIN SQUARES
> > > ctT.fillStyle = "red";
> > > ctT.fillRect(240+prog, 5, 10,10);
> > > prog=prog+15;
> > > jint++;
> > > mvol++;
> > > stopCount=setInterval(countIn,600);
> > > } else {
> > > if (rendScroll){
> > > clearInterval(stopCount);
> > > browserLoadTIME=performance.now();
> > > startScrollAnime();
> > > stopRec=setInterval(recSomeNotes,5);
> > > }
> > > }
> > > }
> > Oops missed this call line outside function.
> > stopCount=setInterval(countIn,600);
> stopCount=setInterval(countIn,600);
> function countIn(){
> REALTIME=(performance.now()-browserLoadTIME)-2400;
> if (REALTIME<0){
> if (mvol==1 || mvol==noteval+1) { metvol=120; } else { metvol=50;}
> noteMessage = [153, 77, metvol];
> outportarr[outportindex].send(noteMessage);
> //DRAWOUT COUNTIN SQUARES
> ctT.fillStyle = "red";
> ctT.fillRect(240+prog, 5, 10,10);
> prog=prog+15;
> jint++;
> mvol++;
> stopCount=setInterval(countIn,600);
> } else {
> if (rendScroll){
> startScrollAnime();
> }
> clearInterval(stopCount);
> stopRec=setInterval(recSomeNotes,5);
> browserLoadTIME=performance.now();
>
> }
> }
This one is real close but the playup never starts, it is strange it is the same call that work without the countIn.
function countIn(){
if (jint<8){
if (mvol==1 || mvol==noteval+1) { metvol=120; } else { metvol=50;}
noteMessage = [153, 77, metvol];
outportarr[outportindex].send(noteMessage);
//DRAWOUT COUNTIN SQUARES
ctT.fillStyle = "red";
ctT.fillRect(240+prog, 5, 10,10);
prog=prog+15;
jint++;
mvol++;
} else {
if (rendScroll){
clearInterval(stopCount);
startScrollAnime();
browserLoadTIME=performance.now();
stopRec=setInterval(recSomeNotes,5);
}
}
}
function recSomeNotes(){
REALTIME=performance.now()-browserLoadTIME;
while(REALTIME>schedTime){
outportarr[outportindex].send(noteMessage[playPos]);
if (echo && mode=="Play"){
pianoKeypressOut();
}
schedTime=copyEv[playPos]+schedTime;
playPos++;
}
if (playPos>copyEv.length) {stop();}
}
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web