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

Use cases for AbortSignal.any() #25

Closed
jasnell opened this issue Jul 30, 2022 · 4 comments
Closed

Use cases for AbortSignal.any() #25

jasnell opened this issue Jul 30, 2022 · 4 comments

Comments

@jasnell
Copy link
Contributor

jasnell commented Jul 30, 2022

One of the active discussions at the whatwg/dom repo is creation of an AbortSignal that can follow other AbortSignals... see whatwg/dom#920

There is a proposal on the table for AbortSignal.any() here: https://github.com/shaseley/abort-signal-any/blob/main/README.md

The key question for this group is whether the proposal looks good and whether wintercg has any feedback for the discussion.

@jasnell
Copy link
Contributor Author

jasnell commented Jul 30, 2022

For Cloudflare Workers, the key usecase that I can imagine supporting is the Timeout case, described in the explainer:

  const signalWithTimeout = AbortSignal.any([signal, AbortSignal.timeout(10_000)]);
  const response = await fetch(tile.url, {signal: signalWithTimeout});

With this example, signalWithTimeout will trigger either when signal is triggered or after 10 seconds, whichever happens first.

I like the layering of this in that it does not modify signal in any outwardly observable way.

One thing that I've asked about before (and would still like to have) is the ability to cancel an AbortSignal -- that is, effectively mark it as no longer be relevant. e.g.

const signal = AbortSignal.timeout(10_000);
// The signal will trigger after 10 seconds.
signal.cancel();  // or signal.close()
// The signal is canceled and will never trigger. All abort event handlers can be released.

This is a separate discussion, however. The two would pair nicely with one another tho.

Cloudflare currently has no plans for implementing TaskSignal so I am largely ignoring all of the use cases in the explainer involving that.

@jasnell
Copy link
Contributor Author

jasnell commented Jul 30, 2022

Another relevant thread here: whatwg/dom#1082

@jasnell jasnell transferred this issue from wintercg/admin Jul 30, 2022
@jasnell
Copy link
Contributor Author

jasnell commented Apr 10, 2024

There's no further action to be done here. AbortSignal.any(...) was added to the spec.

@jasnell jasnell closed this as completed Apr 10, 2024
@mk-pmb
Copy link

mk-pmb commented Apr 10, 2024

Cancelling an AbortSignal sounds interesting. We should then also add a way to re-engage it later. We could use this to enforce timeouts for tasks on low-priority queues only when there are tasks in a higher-priority queue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants