Skip to content

Consider adding a timeout parameter to the AbortController constructor #1110

Open
@shaseley

Description

@shaseley

Feedback from a TAG design review of AbortSignal.timeout() suggested adding timeout as a parameter to the AbortController constructor to improve ergonomics for the case where both a timeout and a controller is needed:

// controller.signal will be aborted after 5 seconds or sooner if `controller.abort()` is called.
let controller = new AbortController({timeout: 5000})`

I agree this would improve ergonomics for that case (even if we add AbortSignal.any()), and it still leaves open the possibility of adding timeout manipulation later (e.g. #1039). FWIW, as I mentioned in the TAG issue, there is prior art on other platforms for doing something like this, e.g. .NET's CancellationTokenSource has a constructor timeout parameter and Go's Context has a WithTimeout function, both of which have similar behavior to what's being proposed here.

Thoughts? Does this seem worth adding, or would it be better to consider this along with timeout manipulation and design them together?

Metadata

Metadata

Assignees

No one assigned

    Labels

    addition/proposalNew features or enhancementsneeds implementer interestMoving the issue forward requires implementers to express interesttopic: abortingAbortController and AbortSignal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions