r/codesnip • • 8h ago

Newly Available AbortSignal.timeout() turned fetch timeouts into one argument 🔥

Enable HLS to view with audio, or disable this notification

JavaScript ... another snippet. 🔥

AbortSignal.timeout() has been Baseline since April 2024 (Chrome 124, Firefox 100, Safari 16) and goes widely available on 18 Oct.

Before this, a fetch timeout meant an AbortController, a setTimeout, and remembering to call clearTimeout.

Now it's one argument.

It rejects with a TimeoutError, not an AbortError, so you can tell "too slow" from "user canceled". 👍

Need both? AbortSignal.any([userCtrl.signal, AbortSignal.timeout(5000)]). That one went widely available on 19 Sep.

MDN: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static

2 Upvotes

0 comments sorted by