[whatwg/dom] Consider adding a timeout parameter to the AbortController constructor (Issue #1110)

Feedback from a [TAG design review of `AbortSignal.timeout()`](https://github.com/w3ctag/design-reviews/issues/711) 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: 

```js
// 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()`](https://github.com/shaseley/abort-signal-any)), and it still leaves open the possibility of adding timeout manipulation later (e.g. #1039). FWIW, as I [mentioned](https://github.com/w3ctag/design-reviews/issues/711#issuecomment-1184627139) 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](https://docs.microsoft.com/en-us/dotnet/api/system.threading.cancellationtokensource.-ctor?view=net-6.0#system-threading-cancellationtokensource-ctor(system-int32)) and Go's `Context` has a [WithTimeout](https://pkg.go.dev/context#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?

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

Message ID: <whatwg/dom/issues/1110@github.com>

Received on Friday, 9 September 2022 18:09:23 UTC