Skip to content

Support AbortSignals in async API #31971

@martinheidegger

Description

@martinheidegger

AbortSignals are used in fetch to abort a request. They are useful to close requests if they don't happen to be necessary. AbortSignals are not widely used yet in the JavaScript ecosystem but they seem like they could be useful if they would find a wider adoption.

A node.js API that comes to mind is if a web framework would provide an abort signal that this could be comfortable to be used as a means to abort a file stream:

createReadStream('file.bin', { signal: req.signal }).pipe(res)

Other places this might be if there was an abort signal for the process that could be used instead of process.on('SIGTERM', ...), ex.:

await readFile('file.bin', { signal: process.abortSignal })

Which could be an easy means to stop allocating money if a CLI tool is used to read a very large file by accident.

At the current point I am not sure at how many places this would be useful, or how useful it would be at each case, but I think opening the discussion has merit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions