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 AbortController #449

Closed
sindresorhus opened this issue Dec 23, 2020 · 3 comments · Fixed by #490
Closed

Support AbortController #449

sindresorhus opened this issue Dec 23, 2020 · 3 comments · Fixed by #490

Comments

@sindresorhus
Copy link
Owner

Node.js is adopting it for everything, so I think we should support it too.

https://developer.mozilla.org/en-US/docs/Web/API/AbortController

Node.js just added support for it in .spawn(): https://nodejs.org/en/blog/release/v15.5.0/

This would not replace the current .cancel() function, in the near-term at least.

@ehmicky
Copy link
Collaborator

ehmicky commented Feb 4, 2022

The signal option was backported to Node 14.18.0. Since Node 12 official support is a little less than 3 months, will we be getting this feature as part of dropping Node 12 support?

When using the signal option, the following could then probably be used:

  • childProcess.cancel() -> AbortController.abort()
  • childProcess.isCanceled and error.isCanceled -> AbortSignal.aborted.

Which would lead to the following action items:

  • Dropping Node 12 support
  • Documenting the signal option
  • Deprecating childProcess.cancel(), childProcess.isCanceled and error.isCanceled
  • Using signal.aborted to set the error message as "canceled" in here

What do you think?

@jopemachine
Copy link
Contributor

jopemachine commented Feb 5, 2022

Dropping Node 12 support

Would it be not possible to just mark this API be available on Node 14.18.0 or higher version, and not dropping Node 12 support? I think dropping Node 12 is okay though because the official maintenance is coming to end as you mentioned.

Deprecating childProcess.cancel(), childProcess.isCanceled and error.isCanceled

In my humble opinion, I think it could feel a little awkward to have two APIs that work the same thing,
but I might feel the existing API could be more human-friendly to users. So, I'm not sure about this..

Using signal.aborted to set the error message as "canceled" in here

When AbortController.abort is called, cancel is called in here by abort event listener, so the error message is set as "canceled" in the line.

@sindresorhus
Copy link
Owner Author

What do you think?

👍

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

Successfully merging a pull request may close this issue.

3 participants