-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AbortSignal.timeout() #711
Comments
We looked at this today, and had a question about the design of this API. Why is this a new factory method (especially on a non constructible class, Also, we wondered if there are any plans for extending or cancelling the timeout. |
The idea is that there is no web-developer-visible
I'm not sure what you mean by this? In general combining works at the level of signals, not controllers.
This was proposed in whatwg/dom#1039 but the use cases were rather esoteric. My current opinion is that it is not necessary to give such full control; if a developer wants that they can just use |
Hi TAG folks, I wanted to provide a couple of updates on this:
Given (1) and the progress on (2) — which works nicely with this API — Chrome is planning to move forward with shipping this API, but look forward to considering any additional feedback as potential additions. |
I accept that having the factory method on AbortSignal makes the simple case where an author only wants to timeout a fetch easy, e.g.:
However, the scenario where the author needs their own AbortController and wants a timeout is more complex, e.g.:
vs having a timeout parameter on the AbortController constructor:
Why not have both? |
A small helper that uses const withTimeout = (signal, timeout) =>
AbortSignal.any([signal, AbortSignal.timeout(timeout)]);
...
const controller = new AbortController();
fetch(url, {signal: withTimeout(controller.signal, 8000))};
// vs.
const controller = new AbortController({ timeout: 8000 });
fetch(url, { signal: controller.signal }); The Prior art on other platforms: .NET's |
This would also potentially be useful if you wanted an increase in timeout on subsequent request retries. Example: |
Any word if the constructor argument is being considered? (Is there an issue we can link to?) |
@plinss I just filed an issue for this: whatwg/dom#1110. |
Hi @shaseley, just circling back on this. Are there any updates? Thank you! |
Hi @domenic, We looked at this again today.
There are several design principles implicitly assumed in this message, and we'd like to discuss them separately, because we may or may not agree, and in any case it's good to get the benefit of a documented discussion that is separate from this particular issue. For example, things like:
|
Braw mornin' TAG!
I'm requesting a TAG review of
AbortSignal.timeout(milliseconds)
.This introduces a new static method,
AbortSignal.timeout(milliseconds)
, which returns a newly-createdAbortSignal
that, aftermilliseconds
milliseconds, becomes automatically aborted. TheAbortSignal
'sreason
property will be a"TimeoutError"
DOMException
. The main motivating use case for this is helping web developers easily time out async operations, such asfetch()
.fetch()
: Add atimeout
option, to prevent hanging whatwg/fetch#951Further details:
We'd prefer the TAG provide feedback as (please delete all but the desired option):
💬 leave review feedback as a comment in this issue and @-notify [@domenic, @shaseley ]
The text was updated successfully, but these errors were encountered: