Skip to content

Creating an already aborted AbortController #959

@jasnell

Description

@jasnell

In Node.js, we have had a couple of use cases pop up recently with the need to mark an AbortController already aborted immediately after creation. Typically, this would be done as: const ac = new AbortController(); ac.abort(); return ac;.

It would be helpful to have a utility that makes this easier...

Either:

const ac = new AbortController({ aborted: true });

or

const ac = AbortController.aborted();

The abort event would never trigger on such objects, which is perfectly fine. We already tell users to check the aborted property before attaching abort listeners.

If the idea seems reasonable, I can work up a PR with the change. I would just need to know which approach (init options vs. static factory function) is preferred.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: abortingAbortController and AbortSignal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions