3 ms·
In the case of something as simple as a bubble sort, you probably could code something to periodically hand control back to the browser to pick up input events,
by onion2k 11y ago
In the case of something as simple as a bubble sort, you probably could code something to periodically hand control back to the browser to pick up input events, but I imagine that would slow it down considerably as you'd need to check every few milliseconds otherwise the user will see some lag. Also, in something more complex inserting breaks would be a lot harder. Why bother when web workers are a good, working solution?
- eueueu 11y agoI'd bet using setTimeout with a 0ms delay every loop wouldn't slow the example down significantly, and would have the desired effect of making the UI responsive.
- wging 11y agoYou might be surprised. There are conditions under which browsers will impose a 4ms minimum delay when you ask for less. I believe it's when you set a timeout within a timeout. Edit: close. https://html.spec.whatwg.org/multipage/webappapis.html#timers https://html.spec.whatwg.org/multipage/webappapis.html#timer... "Timers can be nested; after five such nested timers, however, the interval is forced to be at least four milliseconds."