Skip to content

Use native AbortSignal.timeout (if exists) #261

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

andreas-karlsson
Copy link
Contributor

I had to also update typescript, cause AbortSignal.any wasn't available in the standard lib types for the version we were using.

Comment on lines +23 to +29
const timeoutPolyfill: (typeof AbortSignal)['timeout'] = milliseconds => {
const controller = new AbortController();
setTimeout(() => {
controller.abort(new DOMException('signal timed out', 'TimeoutError'));
}, milliseconds);
return controller.signal;
};
Copy link
Member

Choose a reason for hiding this comment

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

This does not contain the "special stuff" we previously had for NodeJS. Will all node version contain the native AbortSignal.timeout?

this

  // in Node setTimeout returns an object, with an unref function which will prevent the timeout from keeping the process alive
  if (typeof timeoutId === 'object') timeoutId.unref();

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

Successfully merging this pull request may close these issues.

2 participants