Does Node.js automatically propagate AbortSignal to legacy callback‑based APIs?
0 reputation · 28 Jan 2023, 02:27 UTC
Determine whether Node.js can automatically propagate an AbortSignal to legacy callback‑based APIs such as fs.readFile with a callback, which lack a signal option, and understand the implications for graceful cancellation.
While promise‑based APIs accept an AbortSignal and reject with an AbortError when aborted, callback‑based functions do not expose a signal argument, leaving no built‑in mechanism to tie the abort state to the operation. This forces developers to create custom wrappers or use workarounds like Promise.race with a timeout, raising questions about a standardized approach.
Is there a recommended pattern to abort legacy callback‑based operations using AbortSignal? Can a wrapper be implemented that respects the signal without altering the original API? Does Node.js provide any internal mechanism to propagate abort signals to callbacks?