Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #37496
| Newsgroups | comp.lang.javascript |
|---|---|
| Subject | Re: setTimeout( ), with startpoint at t0 |
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
| References | <6ff17c5f-0702-4fef-8f1d-51c44a54fad6@googlegroups.com> <1p7dto6a1nwy0$.1qju8k84zm1j5$.dlg@40tude.net> <af7db9d2-270c-4275-a45c-13eb966309b9@googlegroups.com> |
| Date | 2019-10-03 21:53 +0200 |
| Message-ID | <XnsAADDDEBBDA9EAeejj99@194.109.6.166> (permalink) |
<jonas.thornvall@gmail.com> wrote on 03 Oct 2019 in comp.lang.javascript:
> It is a bit weird though if you write, 8*interval "just the first call
> will take 8 times interval"?
If you think so, don't do it!
=======
Seems to me you are mixing setTimeout() and setInterval() ideas.
setTimeout() strictly has no "interval-time", as it fires only once at most.
If you construct an repeated happening starting at time zero,
the called function should set the setTimeout() again.
========= Using setTimeout():
=========
let timeoutPointer;
const timeoutFunction = () => {
doWhatYouWantItToDo();
timeoutPointer = setTimeout(timeoutFunction,100);
};
timeoutFunction();
==========
A problem could arize here, as doWhatYouWantItToDo() time spend is added to
the repeat time each time. Timing of multiple repeates is inexact in total,
the time between individual repeates is rather exact.
========= Using setInterval():
=========
let intervalPointer;
const intervalFunction = () => {
doWhatYouWantItToDo();
};
intervalPointer = setInterval(intervalFunction,100);
intervalFunction(); /* FIRST TIME ONLY */
==========
A problem could arize here, as doWhatYouWantItToDo() time spend overruns the
repeat time, and you could even have 2 versions in the queue running
directly after eachother. Timing of multiple repeates is rather exact,
individual firings in the queue could be far of.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
setTimeout( ), with startpoint at t0 Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-10-03 04:11 -0700
Re: setTimeout( ), with startpoint at t0 JJ <jj4public@vfemail.net> - 2019-10-03 19:41 +0700
Re: setTimeout( ), with startpoint at t0 Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-10-03 08:34 -0700
Re: setTimeout( ), with startpoint at t0 "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-10-03 21:53 +0200
Re: setTimeout( ), with startpoint at t0 Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-10-03 14:58 -0700
Re: setTimeout( ), with startpoint at t0 Arno Welzel <usenet@arnowelzel.de> - 2019-10-04 13:50 +0200
Re: setTimeout( ), with startpoint at t0 Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-10-04 07:33 -0700
Re: setTimeout( ), with startpoint at t0 Arno Welzel <usenet@arnowelzel.de> - 2019-10-05 13:58 +0200
Re: setTimeout( ), with startpoint at t0 Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-10-05 15:44 -0700
csiph-web