Skip to content

Add AbortSignal.timeout(ms) #951

Closed
@domenic

Description

This has come up in the context of fetch in the past: see whatwg/fetch#951 (comment)

And it has recently come up for streams as well: WICG/serial#122

The proposal is essentially

AbortSignal.timeout = ms => {
  const controller = new AbortController();
  setTimeout(() => controller.abort(), ms);
  return controller.signal;
};

at a high level. Some low-level details:

  • I think we should share the timer task source with setTimeout().
  • I think we should not include the clamping/nesting behavior of setTimeout(), although I'm open to being persuaded otherwise.
  • We should use [EnforceRange] unsigned long long so that you get a quick exception on negative or too-large numbers, instead of clamping negative numbers to zero and taking too-large numbers modulo 2**32.

I'd be happy to write spec text for this if there's implementer interest. Maybe @josepharhar would be interested in implementing this too, similar in spirit to the other recent AbortSignal integration?

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions