The AbortSignal interface represents a signal object that allows you to communicate with a DOM request (such as a fetch request) and abort it if required via an AbortController object.
fetch returns a promise. And JavaScript generally has no concept of “aborting” a promise. So how can we cancel an ongoing fetch? E.g. if the user actions on our site indicate that the fetch isn’t needed any more.
There’s a special built-in object for such purposes: AbortController. It can be used to abort not only fetch, but other asynchronous tasks as well.
There’s a special built-in object for such purposes: AbortController. It can be used to abort not only fetch, but other asynchronous tasks as well.
In such case it is useful to stop sub-processing.Potentially long running processing could benefit from being able to receive such “signal”.
With node.js version 18 the message can also include “reason”, so it has almost perfect symmetry with “throw error”. Throw can send custom error object “up the caller stack”, while “abort” can send message “down the stack”. It could be useful.
an alternative, open source library
This package can be used to synchronize functions that span multiple iterations of the event loop and prevent other code from being executed while your function is waiting.
good podcast discussion and links:
JS logging & error handling with Bret Comnes & Mik Lysenko (JS Party #227) |> Changelog
JS Party #219 - Making moves on supply chain security
Google Analytics alternative that protects your data and your customers' privacy
Take back control with Matomo – a powerful web analytics platform that gives you 100% data ownership.
JS logging & error handling with Bret Comnes & Mik Lysenko (JS Party #227) |> Changelog
JS Party #219 - Making moves on supply chain security
Google Analytics alternative that protects your data and your customers' privacy
Take back control with Matomo – a powerful web analytics platform that gives you 100% data ownership.