There should be a timeout()
or delay()
method on the Promise
object for a cleaner way to add a delay in an async code block.
await Promise.timeout(1000);
equivalent to
await new Promise(t => setTimeout(t, 1000));
There should be a timeout()
or delay()
method on the Promise
object for a cleaner way to add a delay in an async code block.
await Promise.timeout(1000);
equivalent to
await new Promise(t => setTimeout(t, 1000));
setTimeout
isn't in the language, however, and I suspect there will be a lot of pushback if adding any kind of "timer" is attempted.
setTimeout
isn't in the language, however, and I suspect there will be a lot of pushback if adding any kind of "timer" is attempted.
+1 to standardize setTimeout among engines and Promise.timeout if possible.
duktape has example-implementation of eventloop/setTimeout in pure javascript which could serve as polyfill [1]. even if engines implement it suboptimally (duktape example is O(n) timer-insertion), its still better than not having setTimeout at all.
[1] Pure ECMAScript eventloop example