Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #39618
| Path | csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Arno Welzel <usenet@arnowelzel.de> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: setTimeOut and lag adding up. |
| Date | Thu, 11 Mar 2021 12:57:34 +0100 |
| Lines | 34 |
| Message-ID | <iauetdFa43eU1@mid.individual.net> (permalink) |
| References | <fe27709a-9283-4972-a47c-a69b248a748cn@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | individual.net g3kdGsbBnEky6vOalJgHhQT4J/Cvx0IiLWHKr9b4Gpsj7jd7BM |
| Cancel-Lock | sha1:EnV43wQmHl4iRxzQYDi8lX0uzXM= |
| In-Reply-To | <fe27709a-9283-4972-a47c-a69b248a748cn@googlegroups.com> |
| Xref | csiph.com comp.lang.javascript:39618 |
Show key headers only | View raw
Jonas Thörnvall: > I have a question i shift some 12 000 note events. > During 5 min 48 seconds. > > That cause ca 30 seconds of lag in the shift sequence of note intervals/timeout lengths. I could understand the delay add up to some 1000 ms, but 30 000????? > > Can that really be reasonable? Yes. Because setTimeout() will start a timer at the point when it is called. When the handler then needs 0.0025 seconds to deal with the event before the next setTimeout() call is done this sums up to 30 seconds for 12000 events. What you need is setInterval() and clearInterval(): <https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval> <https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearInterval> This call will cause a function to be called *exactly* every n milliseconds, regardless how long this function will take to handle the call. So also make sure that the function will not take longer than the interval is. Also keep in mind that you do NOT call setInterval() again! You call that only ONCE to start the repeated interval calls and to stop it again you use clearInterval() using the ID which you got from setInterval(). -- Arno Welzel https://arnowelzel.de
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
setTimeOut and lag adding up. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-03-10 08:41 -0800
Re: setTimeOut and lag adding up. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-03-10 08:46 -0800
Re: setTimeOut and lag adding up. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-03-10 09:01 -0800
Re: setTimeOut and lag adding up. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-03-10 09:31 -0800
Re: setTimeOut and lag adding up. JJ <jj4public@gmail.com> - 2021-03-11 14:01 +0700
Re: setTimeOut and lag adding up. Arno Welzel <usenet@arnowelzel.de> - 2021-03-11 12:57 +0100
Re: setTimeOut and lag adding up. Silvio <silvio@internet.com> - 2021-03-11 14:17 +0100
Re: setTimeOut and lag adding up. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-03-11 06:07 -0800
Re: setTimeOut and lag adding up. Silvio <silvio@internet.com> - 2021-03-11 16:03 +0100
Re: setTimeOut and lag adding up. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-03-11 07:47 -0800
Re: setTimeOut and lag adding up. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-03-11 05:54 -0800
Re: setTimeOut and lag adding up. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-03-11 06:13 -0800
csiph-web