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

Support AbortSignal.timeout #73

Open
johngeorgewright opened this issue Feb 11, 2023 · 4 comments
Open

Support AbortSignal.timeout #73

johngeorgewright opened this issue Feb 11, 2023 · 4 comments

Comments

@johngeorgewright
Copy link

See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout

The static AbortSignal.timeout() method returns an AbortSignal that will automatically abort after a specified time.

@nekotoriy
Copy link

Important thing, because it's feature breaks safari < 16

@elhardoum
Copy link

Here's a temporary fix:

// safari polyfill
if ("AbortSignal" in window) {
  AbortSignal.timeout = AbortSignal.timeout || ((duration) =>
  {
    const controller = new AbortController;
    setTimeout(() => controller.abort(), duration);
    return controller.signal;
  });
}

elhardoum added a commit to elhardoum/abortcontroller-polyfill that referenced this issue May 10, 2023
@DevSide
Copy link

DevSide commented Aug 1, 2023

@elhardoum This cannot work because your setTimeout will start when AbortSignal.timeout() is called instead of the request itself. It also required a clearTimeout if the request finished earlier.

@nekotoriy, not only Safari < 16: https://caniuse.com/mdn-api_abortsignal_timeout_static

@TechQuery
Copy link

TechQuery commented Apr 30, 2024

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

5 participants