Path: csiph.com!news.swapon.de!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:40:39 +0100 Lines: 28 Message-ID: References: <5189ddb2-f717-40ed-8ab7-d58f84427d8eo@googlegroups.com> <2ed575bd-296e-43df-92ab-09265c196d8bo@googlegroups.com> <84d6ebe8-9a2c-4d91-875f-54f98b5e27b8o@googlegroups.com> <2b5e551d-6a60-48e1-9ade-a8f693709ee7o@googlegroups.com> <112d2238-4adb-419c-b4da-25db9e60391bo@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net 63xSbqAh+Q5DiBhDepB4mA+PvZ3XwnKg986e510Os+52G+r/wl Cancel-Lock: sha1:kkaUucZ8oG+RUNk/bOzT+WldEjY= In-Reply-To: <112d2238-4adb-419c-b4da-25db9e60391bo@googlegroups.com> Xref: csiph.com comp.lang.javascript:39108 Jonas Thörnvall: > Den måndag 2 november 2020 kl. 01:04:59 UTC+1 skrev Arno Welzel: [...] >> Yes - but you tried to use setInterval() with a delay of 0ms to keep a >> function running to poll to UI and then complained that JavaScript is >> slow when polling the UI. > > setInterval is not polling the UI it call the flipcoin function, in my code. > You guys complained i should not do the coinflips in a loop because there was no way to get the attention of DOM, canvas, UI while in loop. You still don't understand it. 1) When you create a loop which will constantly running this will block UI since JavaScript is not multithreaded and event handlers will not execute as long as your code is still busy with other things. 2) If you need something which runs all the time independent from any user input, either create a worker or use setTimeout()/setInterval() to "emulate" a background process by calling a function every x ms which executes only one thing at a time. What fits best for you depends on your application. -- Arno Welzel https://arnowelzel.de