Skip to content
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

Introduce AbortSignal.timeout() #1032

Merged
merged 1 commit into from
Feb 2, 2022
Merged

Introduce AbortSignal.timeout() #1032

merged 1 commit into from
Feb 2, 2022

Conversation

domenic
Copy link
Member

@domenic domenic commented Nov 19, 2021

Closes #951.

Mini-explainer for TAG review/blink-dev purposes:

This introduces a new static method, AbortSignal.timeout(milliseconds), which returns a newly-created AbortSignal that, after milliseconds milliseconds, becomes automatically aborted. The AbortSignal's reason property will be a "TimeoutError" DOMException.

The main motivating use case for this is helping web developers easily time out async operations, such as fetch(). For example, now you can write:

fetch(url, { signal: AbortSignal.timeout(10_000) });

to ensure your fetch operation has a 10-second timeout. A more full example would be:

try {
  const res = await fetch(url, { signal: AbortSignal.timeout(10_000) });
  const result = await res.text();
  // ...
} catch (e) {
  if (e.name === "TimeoutError") {
    // It took more than 10 seconds to get the result!
  } else if (e.name === "AbortError") {
    // The fetch was explicitly aborted, e.g. by the user pressing the stop button!
  } else {
    // Something horrible went wrong, like a network error!
  }
}

This has come up in the context of several specs; see discussions on fetch at whatwg/fetch#951 and streams at WICG/serial#122 (comment). It is generally helpful for any operation that takes an AbortSignal, including web-developer-defined operations.

Interesting points of discussion are:

  • It is specifically important that the reason be a "TimeoutError" DOMException, instead of the default-for-AbortSignal "AbortError" DOMException. This is because developers almost always want to discriminate between those two: a timeout is a proper failure which they might show to users, whereas an abort usually more of a "third state" (alongside success and failure) which usually they don't want to tell users about. (E.g., because the user is the one that caused the abort in the first place.)

  • We treat the milliseconds argument the same as scheduler.postTask(), and almost the same as setTimeout(). (The difference is, we don't have the nested-clamping-to-4-ms behavior that setTimeout() does.) In particular this means that the timer does not advance while the document is in bfcache, or the worker is suspended. See Introduce AbortSignal.timeout() #1032 (comment) for the reasoning there.

Future work: this feature would benefit greatly from a solution for combining AbortSignals, so that people could have an operation that aborts on either a timeout or an explicit abort. For example, something like this:

// NOT REAL CODE, YET:
const controller = new AbortController();
fetch(url, { signal: AbortSignal.all([AbortSignal.timeout(10_000), controller.signal]) });

abortButton.onclick = () => controller.abort();

Unfortunately there are a lot of possible shapes for such an API and so we still need to do a bit more work and research to find the best one. That's tracked in #920. Until then, people can combine such signals manually, as discussed in that issue thread.

(See WHATWG Working Mode: Changes for more details.)


Now-obsolete discussion of "Subtle things to deal with"
  • Need to export "timer task source" from HTML
  • What portions of the delay logic from setTimeout and postTask should we port over here?
    • I so far ported: wait milliseconds; ensure ordering within a global; and allow implementation-defined extra waiting (e.g. to align on CPU wakeups or allow throttling while in the background).
    • I'm on the fence as to whether we should port suspending the timer while the document is in bfcache or the worker is suspended. For e.g. fetch timeouts, it doesn't seem to matter much whether you were in bfcache/suspended; if the server took 30 wall-clock seconds to respond, you probably want to give up. On the other hand, it might be strange (or hard to implement) for this timer mechanism to behave differently from others on the platform.
    • Should these timers impact idle callback deadline computation? postTask timers do not, but that may be an oversight. @shaseley @noamr
    • I think that, like postTask, we should not port the nesting and clamping messiness from setTimeout. The implementation-defined extra time is enough.
  • Probably it's time to centralize this delay logic so that this spec, HTML, and postTask can reuse it. But we'd need to decide on the above questions first.

Preview | Diff


Preview | Diff

@shaseley
Copy link
Contributor

Ah, yeah it's an oversight if postTask timers don't affect the idle deadline computation, and they do in our implementation. Looks like we'll need to insert an entry into that map, but it looks like that might also require moving handle outside of setTimeout spec?

@domenic
Copy link
Member Author

domenic commented Nov 19, 2021

Yeah, in that case I will work on a HTML spec PR pulling out the common infrastructure. For now it will behave exactly like the shared parts of postTask/setTimeout. If we decide AbortSignal.timeout() should behave the same as those with regard to bfcache/suspended workers then this PR can just use that; otherwise we can add a flag.

domenic added a commit to whatwg/html that referenced this pull request Nov 19, 2021
This factors out a new algorithm which can be used by postTask() (https://wicg.github.io/scheduling-apis/#schedule-a-posttask-task) and AbortSignal.timeout() (whatwg/dom#1032), ensuring that they correctly contribute to idle deadline computation and in general share all the appropriate logic with setTimeout() and setInterval().

This also exports the "timer task source" term since AbortSignal.abort() will want to use that.
@domenic
Copy link
Member Author

domenic commented Nov 19, 2021

I did the centralization work at whatwg/html#7349, and sent WICG/scheduling-apis#54 plus updated this PR to match.

Now this PR does pause the timeout while in bfcache/while the worker is suspended. We should discuss whether that's a good idea or not; it's certainly the path of least resistance.

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! And yeah, Mozilla can be considered supportive.

dom.bs Outdated Show resolved Hide resolved
jasnell added a commit to jasnell/node that referenced this pull request Nov 20, 2021
Refs: whatwg/dom#1032
Signed-off-by: James M Snell <jasnell@gmail.com>
jasnell added a commit to jasnell/node that referenced this pull request Nov 21, 2021
Refs: whatwg/dom#1032
Signed-off-by: James M Snell <jasnell@gmail.com>
jasnell added a commit to jasnell/node that referenced this pull request Nov 21, 2021
Refs: whatwg/dom#1032
Signed-off-by: James M Snell <jasnell@gmail.com>
domenic added a commit to whatwg/html that referenced this pull request Nov 23, 2021
This factors out a new algorithm which can be used by postTask() (https://wicg.github.io/scheduling-apis/#schedule-a-posttask-task) and AbortSignal.timeout() (whatwg/dom#1032), ensuring that they correctly contribute to idle deadline computation and in general share all the appropriate logic with setTimeout() and setInterval().

This also exports the "timer task source" term since AbortSignal.abort() will want to use that.
@domenic
Copy link
Member Author

domenic commented Nov 23, 2021

I was going to write a big comment with the pros/cons of suspending while in bfcache/in a worker. But in the end it mostly ended up with pros for suspended. So I am currently advocating we keep the setTimeout() behavior here, i.e. if you do AbortSignal.timeout(10_000), you need to spend 10 seconds active before the signal aborts, not 10 seconds wall time.

Here's was my thought process on the pros/cons of suspending:

  • (+) Matches setTimeout() so might be more expected for developers
  • (+) Easier to spec and probably easier to implement
  • (+/-) Avoids "timer storms" upon reactivation
  • (-? but not really) Seemingly doesn't match the primary use case that well, of erroring an operation if it took too long. E.g. if you use fetch(..., { signal: AbortSignal.timeout(30_000) }), and the server still hasn't responded after 30 seconds, you don't care whether some of those 30 seconds were spent in bfcache: the server is probably not going to respond.
    • This is why the "timer storms" argument is both a pro and a con: having a bunch of stuff get aborted upon bfcache restore, because it took too long, actually seems OK! It's very different than running a bunch of code upon bfcache restore, which is what you would expect with setTimeout().
    • On the other hand, I believe this scenario isn't realistic: if you go into bfcache, I'm pretty sure all ongoing fetches will be aborted immediately anyway. (Or maybe we just won't let you go into bfcache with ongoing fetches; not sure.)
    • Finally, what really swung this for me was remembering that we use fetch()'s signal for more than just the network operation: we use it for, e.g., JSON decoding or other consume-body operations. So consider the scenario where the server responds, and perhaps even all of the body is read into memory. But then we go into bfcache, before the promise returned from json() can fulfill. If we spend a minute in bfcache and then go back, we don't really want the promise to reject; we want it to do that last tiny bit of work, and fulfill! I think this is probably a specific case of a more general scenario, possibly involving non-browser APIs that use AbortSignal and care about timeouts.

@shaseley, does this reasoning seem reasonable to you? I'd like to have your blessing on our decision here, as the person who has thought most about these sorts of timing and scheduling things in Chromium :)

@shaseley
Copy link
Contributor

Yep, this sounds reasonable; suspending in bfcache LGTM. These roughly match what I've been thinking, and great point about how fetch's signal is used for more than just the network operation. A few more thoughts inline below:

Here's was my thought process on the pros/cons of suspending:

  • (+) Matches setTimeout() so might be more expected for developers

Note: this is unfortunately broken in in Chromium, but I do like the consistency.

  • (+) Easier to spec and probably easier to implement

  • (+/-) Avoids "timer storms" upon reactivation

  • (-? but not really) Seemingly doesn't match the primary use case that well, of erroring an operation if it took too long. E.g. if you use fetch(..., { signal: AbortSignal.timeout(30_000) }), and the server still hasn't responded after 30 seconds, you don't care whether some of those 30 seconds were spent in bfcache: the server is probably not going to respond.

    • This is why the "timer storms" argument is both a pro and a con: having a bunch of stuff get aborted upon bfcache restore, because it took too long, actually seems OK! It's very different than running a bunch of code upon bfcache restore, which is what you would expect with setTimeout().

Yeah aborting stuff on restore would be good in this scenario, although timer storms could still result if these signals have abort event listeners that do a bunch of work in response to the error.

  • On the other hand, I believe this scenario isn't realistic: if you go into bfcache, I'm pretty sure all ongoing fetches will be aborted immediately anyway. (Or maybe we just won't let you go into bfcache with ongoing fetches; not sure.)

We're recommending that devs close connections in pagehide, and that article is leading me to believe pages with ongoing fetches aren't eligible for bfcache in Chromium. I'm not sure about other browsers.

Combining a timeout signal with one that gets aborted on pagehide seems like maybe a good option? If we can make it more ergonomic to combine signals that would be even better. (Although, you might get into scenarios where you have the data but end up aborting the processing like you're describing below.)

  • Finally, what really swung this for me was remembering that we use fetch()'s signal for more than just the network operation: we use it for, e.g., JSON decoding or other consume-body operations. So consider the scenario where the server responds, and perhaps even all of the body is read into memory. But then we go into bfcache, before the promise returned from json() can fulfill. If we spend a minute in bfcache and then go back, we don't really want the promise to reject; we want it to do that last tiny bit of work, and fulfill! I think this is probably a specific case of a more general scenario, possibly involving non-browser APIs that use AbortSignal and care about timeouts.

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main thing I'm worried about for Firefox is that I think @farre or @smaug---- at some point mentioned to me that the clamping logic sits pretty deep in our timeout code. And beyond that, I worry that if we don't enforce clamping for these new timer mechanisms we'll eventually end up back there due to misbehaving websites. But perhaps if no browser budges it's feasible to hold the door.

dom.bs Outdated Show resolved Hide resolved
jasnell added a commit to jasnell/node that referenced this pull request Nov 24, 2021
Refs: whatwg/dom#1032
Signed-off-by: James M Snell <jasnell@gmail.com>
@jasnell
Copy link
Contributor

jasnell commented Nov 24, 2021

You can add Node.js and Cloudflare Workers to the list of runtime implementations in support of this. I have PRs pending to land in both environments implementing the setTimeout() compatible behavior.

domenic added a commit to whatwg/html that referenced this pull request Nov 24, 2021
This factors out a new algorithm which can be used by postTask() (https://wicg.github.io/scheduling-apis/#schedule-a-posttask-task) and AbortSignal.timeout() (whatwg/dom#1032), ensuring that they correctly contribute to idle deadline computation and in general share all the appropriate logic with setTimeout() and setInterval().

This also exports the "timer task source" term since AbortSignal.abort() will want to use that.
@domenic
Copy link
Member Author

domenic commented Nov 24, 2021

The main thing I'm worried about for Firefox is that I think @farre or @smaug---- at some point mentioned to me that the clamping logic sits pretty deep in our timeout code. And beyond that, I worry that if we don't enforce clamping for these new timer mechanisms we'll eventually end up back there due to misbehaving websites. But perhaps if no browser budges it's feasible to hold the door.

I feel like we (Mozilla and Chromium) discussed this in the context of postTask() and our conclusion was that the allowance for implementation-defined waiting was enough, at least to start with.

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that makes sense.

@annevk annevk added the needs tests Moving the issue forward requires someone to write tests label Nov 24, 2021
@domenic
Copy link
Member Author

domenic commented Nov 24, 2021

Alright, I've updated this with a mini-explainer. All that remains are someone to write some web platform tests, probably as part of an implementation :)

@smaug----
Copy link
Collaborator

So the signal on the fetch (in the example) would be aborted even if the fetch() succeeds, abort would just happen when the timeout happens to run? Isn't that error prone, getting abort event, even though the fetch() itself has succeeded?

@domenic
Copy link
Member Author

domenic commented Nov 24, 2021

I'm not sure I understand the concern. Nobody else is listening for the abort event in the example... and if they were, then the contract is that the AbortSignal should signal abort to both the fetch (which ignores it) and that other thing (which doesn't), so it seems like it's working as intended.

@smaug----
Copy link
Collaborator

The concern, which may not be that major, is just that one gets now always an aborted signal eventually, so the event listener on the signal is called, even though fetch() or other APIs using signal succeed.
One could think of some way to cancel the timeout.

@jasnell
Copy link
Contributor

jasnell commented Nov 25, 2021

I think the issue is more that the timer can continue well after the set of operations completed successfully. Take a pathological case where I create an AbortSignal with a timeout of 20 minutes and I attach a handler to it with a closure.

const signal = AbortSignal.timeout(1_200_000);
signal.addEventListener('abort', () => {
  throw signal.reason;
});

The complete set of operations that I pass the signal to complete successfully, but the internal timer for the signal keeps right on going, holding the AbortSignal and the closure (along with whatever memory it's closing over) for the whole 20 minutes. Then, it unconditionally throws a synchronous error.

Ideally there would be a way of canceling the timeout. Obviously that doesn't help with the closure holding on to things but it ensures that the underlying timer it at least no holding the reference for way longer than it needs to.

const signal = AbortSignal.timeout(1_200_000);
await fetch('http://example.org', { signal });
signal.clearTimeout();

This case is similar to why we allowed adding an AbortSignal to addEventListener() itself. We can even follow a similar pattern here if necessary:

const cancelAbort = AbortController();
const signal = AbortSignal.timeout(1_200_000, { signal: cancelAbort.signal });
signal.addEventListener('abort', () => {
  throw signal.reason;
}, { signal: cancelAbort.signal });
await fetch('http://example.org', { signal });
cancelAbort.abort();

Granted, this doesn't prevent the pathological case but it provides a Right Way To Do It alternative.

@domenic
Copy link
Member Author

domenic commented Nov 25, 2021

I'm still having trouble understanding the concern. Could someone produce a semi-realistic example of what someone might do with the current proposal, and how they think that the code would give unexpected results?

@jasnell
Copy link
Contributor

jasnell commented Nov 25, 2021

Is this example not realistic?

const signal = AbortSignal.timeout(1_200_000);
signal.addEventListener('abort', () => { throw signal.reason; });
await fetch('http://example.org', { signal });

@domenic
Copy link
Member Author

domenic commented Nov 25, 2021

Well, I'm not sure what the consumer on the second line is trying to do. What about that example is not working as expected? I.e. what are the expected results, vs. the actual results in this proposal?

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jan 31, 2022
AbortSignal.timeout is a static method that creates a new AbortSignal
that is automatically aborted after a specified duration. The
implementation is essentially PostDelayedTask(SignalAbort, ms).

Throttling: this API is specced to use the timer task source, but there
are three internally due to our throttling implementation. We use
immediate for the timeout == 0 case and high nesting for timeount > 0
(the typical case), i.e. all non-zero timeouts are eligible for
throttling (Note: this matches scheduler.postTask()).

Spec PR: whatwg/dom#1032
I2P: https://groups.google.com/a/chromium.org/g/blink-dev/c/9Y290P1WimY/m/bru989iAAgAJ

Bug: 1181925
Change-Id: I192d82a8bf12c368abcd47ae6c50e80f50654cf9
danielleadams pushed a commit to nodejs/node that referenced this pull request Feb 1, 2022
Refs: whatwg/dom#1032
Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: #40899
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Feb 1, 2022
AbortSignal.timeout is a static method that creates a new AbortSignal
that is automatically aborted after a specified duration. The
implementation is essentially PostDelayedTask(SignalAbort, ms).

Throttling: this API is specced to use the timer task source, but there
are three internally due to our throttling implementation. We use
immediate for the timeout == 0 case and high nesting for timeount > 0
(the typical case), i.e. all non-zero timeouts are eligible for
throttling (Note: this matches scheduler.postTask()).

Spec PR: whatwg/dom#1032
I2P: https://groups.google.com/a/chromium.org/g/blink-dev/c/9Y290P1WimY/m/bru989iAAgAJ

Bug: 1181925
Change-Id: I192d82a8bf12c368abcd47ae6c50e80f50654cf9
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Feb 1, 2022
AbortSignal.timeout is a static method that creates a new AbortSignal
that is automatically aborted after a specified duration. The
implementation is essentially PostDelayedTask(SignalAbort, ms).

Throttling: this API is specced to use the timer task source, but there
are three internally due to our throttling implementation. We use
immediate for the timeout == 0 case and high nesting for timeount > 0
(the typical case), i.e. all non-zero timeouts are eligible for
throttling (Note: this matches scheduler.postTask()).

Spec PR: whatwg/dom#1032
I2P: https://groups.google.com/a/chromium.org/g/blink-dev/c/9Y290P1WimY/m/bru989iAAgAJ

Bug: 1181925
Change-Id: I192d82a8bf12c368abcd47ae6c50e80f50654cf9
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Feb 1, 2022
AbortSignal.timeout is a static method that creates a new AbortSignal
that is automatically aborted after a specified duration. The
implementation is essentially PostDelayedTask(SignalAbort, ms).

Throttling: this API is specced to use the timer task source, but there
are three internally due to our throttling implementation. We use
immediate for the timeout == 0 case and high nesting for timeount > 0
(the typical case), i.e. all non-zero timeouts are eligible for
throttling (Note: this matches scheduler.postTask()).

Spec PR: whatwg/dom#1032
I2P: https://groups.google.com/a/chromium.org/g/blink-dev/c/9Y290P1WimY/m/bru989iAAgAJ

Bug: 1181925
Change-Id: I192d82a8bf12c368abcd47ae6c50e80f50654cf9
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Feb 2, 2022
AbortSignal.timeout is a static method that creates a new AbortSignal
that is automatically aborted after a specified duration. The
implementation is essentially PostDelayedTask(SignalAbort, ms).

Throttling: this API is specced to use the timer task source, but there
are three internally due to our throttling implementation. We use
immediate for the timeout == 0 case and high nesting for timeount > 0
(the typical case), i.e. all non-zero timeouts are eligible for
throttling (Note: this matches scheduler.postTask()).

Spec PR: whatwg/dom#1032
I2P: https://groups.google.com/a/chromium.org/g/blink-dev/c/9Y290P1WimY/m/bru989iAAgAJ

Bug: 1181925
Change-Id: I192d82a8bf12c368abcd47ae6c50e80f50654cf9
aarongable pushed a commit to chromium/chromium that referenced this pull request Feb 2, 2022
AbortSignal.timeout is a static method that creates a new AbortSignal
that is automatically aborted after a specified duration. The
implementation is essentially PostDelayedTask(SignalAbort, ms).

Throttling: this API is specced to use the timer task source, but there
are three internally due to our throttling implementation. We use
immediate for the timeout == 0 case and high nesting for timeount > 0
(the typical case), i.e. all non-zero timeouts are eligible for
throttling (Note: this matches scheduler.postTask()).

Spec PR: whatwg/dom#1032
I2P: https://groups.google.com/a/chromium.org/g/blink-dev/c/9Y290P1WimY/m/bru989iAAgAJ

Bug: 1181925
Change-Id: I192d82a8bf12c368abcd47ae6c50e80f50654cf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3425124
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Scott Haseley <shaseley@chromium.org>
Cr-Commit-Position: refs/heads/main@{#966406}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Feb 2, 2022
AbortSignal.timeout is a static method that creates a new AbortSignal
that is automatically aborted after a specified duration. The
implementation is essentially PostDelayedTask(SignalAbort, ms).

Throttling: this API is specced to use the timer task source, but there
are three internally due to our throttling implementation. We use
immediate for the timeout == 0 case and high nesting for timeount > 0
(the typical case), i.e. all non-zero timeouts are eligible for
throttling (Note: this matches scheduler.postTask()).

Spec PR: whatwg/dom#1032
I2P: https://groups.google.com/a/chromium.org/g/blink-dev/c/9Y290P1WimY/m/bru989iAAgAJ

Bug: 1181925
Change-Id: I192d82a8bf12c368abcd47ae6c50e80f50654cf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3425124
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Scott Haseley <shaseley@chromium.org>
Cr-Commit-Position: refs/heads/main@{#966406}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Feb 2, 2022
AbortSignal.timeout is a static method that creates a new AbortSignal
that is automatically aborted after a specified duration. The
implementation is essentially PostDelayedTask(SignalAbort, ms).

Throttling: this API is specced to use the timer task source, but there
are three internally due to our throttling implementation. We use
immediate for the timeout == 0 case and high nesting for timeount > 0
(the typical case), i.e. all non-zero timeouts are eligible for
throttling (Note: this matches scheduler.postTask()).

Spec PR: whatwg/dom#1032
I2P: https://groups.google.com/a/chromium.org/g/blink-dev/c/9Y290P1WimY/m/bru989iAAgAJ

Bug: 1181925
Change-Id: I192d82a8bf12c368abcd47ae6c50e80f50654cf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3425124
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Scott Haseley <shaseley@chromium.org>
Cr-Commit-Position: refs/heads/main@{#966406}
@domenic
Copy link
Member Author

domenic commented Feb 2, 2022

Tests have landed! Merging, and will file browser bugs and edit the OP with them momentarily.

@domenic domenic merged commit db4088a into main Feb 2, 2022
@domenic domenic deleted the abortsignal-timeout branch February 2, 2022 22:08
mattwoodrow pushed a commit to mattwoodrow/wpt that referenced this pull request Feb 15, 2022
AbortSignal.timeout is a static method that creates a new AbortSignal
that is automatically aborted after a specified duration. The
implementation is essentially PostDelayedTask(SignalAbort, ms).

Throttling: this API is specced to use the timer task source, but there
are three internally due to our throttling implementation. We use
immediate for the timeout == 0 case and high nesting for timeount > 0
(the typical case), i.e. all non-zero timeouts are eligible for
throttling (Note: this matches scheduler.postTask()).

Spec PR: whatwg/dom#1032
I2P: https://groups.google.com/a/chromium.org/g/blink-dev/c/9Y290P1WimY/m/bru989iAAgAJ

Bug: 1181925
Change-Id: I192d82a8bf12c368abcd47ae6c50e80f50654cf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3425124
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Scott Haseley <shaseley@chromium.org>
Cr-Commit-Position: refs/heads/main@{#966406}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Feb 26, 2022
Automatic update from web-platform-tests
Implement AbortSignal.timeout

AbortSignal.timeout is a static method that creates a new AbortSignal
that is automatically aborted after a specified duration. The
implementation is essentially PostDelayedTask(SignalAbort, ms).

Throttling: this API is specced to use the timer task source, but there
are three internally due to our throttling implementation. We use
immediate for the timeout == 0 case and high nesting for timeount > 0
(the typical case), i.e. all non-zero timeouts are eligible for
throttling (Note: this matches scheduler.postTask()).

Spec PR: whatwg/dom#1032
I2P: https://groups.google.com/a/chromium.org/g/blink-dev/c/9Y290P1WimY/m/bru989iAAgAJ

Bug: 1181925
Change-Id: I192d82a8bf12c368abcd47ae6c50e80f50654cf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3425124
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Scott Haseley <shaseley@chromium.org>
Cr-Commit-Position: refs/heads/main@{#966406}

--

wpt-commits: 2b811aa5c2695cb3fd6f895cdce5952d1e0dd22d
wpt-pr: 32622
DanielRyanSmith pushed a commit to DanielRyanSmith/wpt that referenced this pull request Feb 28, 2022
AbortSignal.timeout is a static method that creates a new AbortSignal
that is automatically aborted after a specified duration. The
implementation is essentially PostDelayedTask(SignalAbort, ms).

Throttling: this API is specced to use the timer task source, but there
are three internally due to our throttling implementation. We use
immediate for the timeout == 0 case and high nesting for timeount > 0
(the typical case), i.e. all non-zero timeouts are eligible for
throttling (Note: this matches scheduler.postTask()).

Spec PR: whatwg/dom#1032
I2P: https://groups.google.com/a/chromium.org/g/blink-dev/c/9Y290P1WimY/m/bru989iAAgAJ

Bug: 1181925
Change-Id: I192d82a8bf12c368abcd47ae6c50e80f50654cf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3425124
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Scott Haseley <shaseley@chromium.org>
Cr-Commit-Position: refs/heads/main@{#966406}
jamienicol pushed a commit to jamienicol/gecko that referenced this pull request Mar 1, 2022
Automatic update from web-platform-tests
Implement AbortSignal.timeout

AbortSignal.timeout is a static method that creates a new AbortSignal
that is automatically aborted after a specified duration. The
implementation is essentially PostDelayedTask(SignalAbort, ms).

Throttling: this API is specced to use the timer task source, but there
are three internally due to our throttling implementation. We use
immediate for the timeout == 0 case and high nesting for timeount > 0
(the typical case), i.e. all non-zero timeouts are eligible for
throttling (Note: this matches scheduler.postTask()).

Spec PR: whatwg/dom#1032
I2P: https://groups.google.com/a/chromium.org/g/blink-dev/c/9Y290P1WimY/m/bru989iAAgAJ

Bug: 1181925
Change-Id: I192d82a8bf12c368abcd47ae6c50e80f50654cf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3425124
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Scott Haseley <shaseley@chromium.org>
Cr-Commit-Position: refs/heads/main@{#966406}

--

wpt-commits: 2b811aa5c2695cb3fd6f895cdce5952d1e0dd22d
wpt-pr: 32622
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Mar 8, 2022
Automatic update from web-platform-tests
Implement AbortSignal.timeout

AbortSignal.timeout is a static method that creates a new AbortSignal
that is automatically aborted after a specified duration. The
implementation is essentially PostDelayedTask(SignalAbort, ms).

Throttling: this API is specced to use the timer task source, but there
are three internally due to our throttling implementation. We use
immediate for the timeout == 0 case and high nesting for timeount > 0
(the typical case), i.e. all non-zero timeouts are eligible for
throttling (Note: this matches scheduler.postTask()).

Spec PR: whatwg/dom#1032
I2P: https://groups.google.com/a/chromium.org/g/blink-dev/c/9Y290P1WimY/m/bru989iAAgAJ

Bug: 1181925
Change-Id: I192d82a8bf12c368abcd47ae6c50e80f50654cf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3425124
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Scott Haseley <shaseley@chromium.org>
Cr-Commit-Position: refs/heads/main@{#966406}

--

wpt-commits: 2b811aa5c2695cb3fd6f895cdce5952d1e0dd22d
wpt-pr: 32622
jamienicol pushed a commit to jamienicol/gecko that referenced this pull request Mar 8, 2022
Automatic update from web-platform-tests
Implement AbortSignal.timeout

AbortSignal.timeout is a static method that creates a new AbortSignal
that is automatically aborted after a specified duration. The
implementation is essentially PostDelayedTask(SignalAbort, ms).

Throttling: this API is specced to use the timer task source, but there
are three internally due to our throttling implementation. We use
immediate for the timeout == 0 case and high nesting for timeount > 0
(the typical case), i.e. all non-zero timeouts are eligible for
throttling (Note: this matches scheduler.postTask()).

Spec PR: whatwg/dom#1032
I2P: https://groups.google.com/a/chromium.org/g/blink-dev/c/9Y290P1WimY/m/bru989iAAgAJ

Bug: 1181925
Change-Id: I192d82a8bf12c368abcd47ae6c50e80f50654cf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3425124
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Scott Haseley <shaseley@chromium.org>
Cr-Commit-Position: refs/heads/main@{#966406}

--

wpt-commits: 2b811aa5c2695cb3fd6f895cdce5952d1e0dd22d
wpt-pr: 32622
mfreed7 pushed a commit to mfreed7/html that referenced this pull request Jun 3, 2022
This factors out a new algorithm which can be used by postTask() (https://wicg.github.io/scheduling-apis/#schedule-a-posttask-task) and AbortSignal.timeout() (whatwg/dom#1032), ensuring that they correctly contribute to idle deadline computation and in general share all the appropriate logic with setTimeout() and setInterval().

This also exports the "timer task source" term since AbortSignal.abort() will want to use that.
mjfroman pushed a commit to mjfroman/moz-libwebrtc-third-party that referenced this pull request Oct 14, 2022
AbortSignal.timeout is a static method that creates a new AbortSignal
that is automatically aborted after a specified duration. The
implementation is essentially PostDelayedTask(SignalAbort, ms).

Throttling: this API is specced to use the timer task source, but there
are three internally due to our throttling implementation. We use
immediate for the timeout == 0 case and high nesting for timeount > 0
(the typical case), i.e. all non-zero timeouts are eligible for
throttling (Note: this matches scheduler.postTask()).

Spec PR: whatwg/dom#1032
I2P: https://groups.google.com/a/chromium.org/g/blink-dev/c/9Y290P1WimY/m/bru989iAAgAJ

Bug: 1181925
Change-Id: I192d82a8bf12c368abcd47ae6c50e80f50654cf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3425124
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Scott Haseley <shaseley@chromium.org>
Cr-Commit-Position: refs/heads/main@{#966406}
NOKEYCHECK=True
GitOrigin-RevId: 6418fb5de0252c4cca60b9027237ad24f074465a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs tests Moving the issue forward requires someone to write tests topic: aborting AbortController and AbortSignal
Development

Successfully merging this pull request may close these issues.

Add AbortSignal.timeout(ms)
5 participants