Skip to content

.tip

· one of the small things

fetch has no timeout, so AbortController is the timeout

If a server accepts the connection and never answers, a fetch to it waits forever, and so does everything awaiting that fetch.

const res = await fetch(url, { signal: AbortSignal.timeout(5000) });

Every current runtime has AbortSignal.timeout. Hand the same signal to anything downstream that accepts one, so cancelling the request also cancels the work it kicked off.

javascripthttp