For Node.js we implemented this as an alternative to the current setTimeout:
const { setTimeout } = require('timers/promises')
// Or
import { setTimeout } from 'timers/promises'
Then...
await setTimeout(500)
It works very well and is straightforward to implement on the browser-side.
On Sun, Dec 27, 2020, 09:56 Cyril Auburtin <[email protected]> wrote:
> Follow up on https://esdiscuss.org/topic/promise-returning-delay-function
>
> I think we really need that function, with AbortController support
>
> We could do things like
>
> ```js
> const abortFetch = new AbortController();
> const abortTimeout = new AbortController();
>
> await Promise.race([
> Promise.delay(5000, {signal: abortTimeout.signal}),
> fetch(url, {signal: abortFetch.signal}).then(r => r.json()).then(...),
> ])
> .finally(() => {
> abortFetch.abort();
> abortTimeout.abort(); // avoid mem leaks, that would call clearTimeout
> under the hood
> })
> ```
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss