Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.javascript Subject: Re: Doing what you suggest, the timing for function calls using setInterval is just awful slow why????? Date: Mon, 2 Nov 2020 11:37:05 +0100 Lines: 31 Message-ID: References: <5189ddb2-f717-40ed-8ab7-d58f84427d8eo@googlegroups.com> <2ed575bd-296e-43df-92ab-09265c196d8bo@googlegroups.com> <2c544c3a-2dea-472e-87cb-9578fd09072bo@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net ALaXdbO6FrLhAM6OXJPIjAEGrjr4+QSwf1gNs4TK95BWokOHo6 Cancel-Lock: sha1:H+r7o7GSbOQL9SIS6cE+fKrQ83w= In-Reply-To: Xref: csiph.com comp.lang.javascript:39107 Jonas Thörnvall: [...] > Yeah... So how did you mean i should use setTimeout and setInterval. You should not do anything just because someone tells you to do so. First you should understand what an event driven UI is and that JavaScript is not multithreaded. If your application needs to do something periodically but also should handle user input, you have only two choices in JavaScript: Use setInterval() or setTimeout() to keep things going by calling some function which keeps the background stuff running by executing only one thing at a time for each timer trigger so the browser still can pass events to the event handlers. As in there is an animation running constantly but at the same time user input is possible as well to enable full screen view or stop and reset the animation. OR: Use workers (see ) to start a script as background process. -- Arno Welzel https://arnowelzel.de