Promise-returning delay function

Cyril Auburtin cyril.auburtin at gmail.com
Sun Dec 27 17:56:09 UTC 2020


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
  })
```
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20201227/2b0fd72b/attachment.html>


More information about the es-discuss mailing list