[whatwg/dom] Add AbortSignal.timeout(ms) (#951)

This has come up in the context of fetch in the past: see https://github.com/whatwg/fetch/issues/951#issuecomment-541369940

And it has recently come up for streams as well: https://github.com/WICG/serial/issues/122

The proposal is essentially

```js
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?

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/951

Received on Wednesday, 24 February 2021 22:27:44 UTC