FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

lib: add AbortSignal.timeout by jasnell · Pull Request #40899 · nodejs/node · GitHub

/ node Public

lib: add AbortSignal.timeout - #40899

Closed
jasnell wants to merge 2 commits into
nodejs:masterfrom
jasnell:abortsignal-timeout
Closed

lib: add AbortSignal.timeout#40899
jasnell wants to merge 2 commits into
nodejs:masterfrom
jasnell:abortsignal-timeout

Conversation

jasnell commented Nov 20, 2021
edited by VoltrexKeyva
Loading

Copy link
Copy Markdown
Member

Builds on from the AbortSignal.reason PR, which should land first.

whatwg/dom#1032 introduces a new AbortSignal.timeout() that returns an AbortSignal that triggers in the given number of milliseconds.

nodejs-github-bot added the needs-ci PRs that need a full CI run. label Nov 20, 2021
Comment thread doc/api/globals.md Outdated
Comment thread lib/internal/abort_controller.js Outdated
Comment thread lib/internal/abort_controller.js Outdated

Copy link
Copy Markdown
Member

I am not too happy this makes it hard to determine an error is cancellation

jasnell commented Nov 21, 2021

Copy link
Copy Markdown
Member Author

I am not too happy this makes it hard to determine an error is cancellation

I don't understand. This sets the reason to a TimeoutError whose stack clearly shows it coming from an AbortSignal. And the code still has to be written to use the reason, which is optional. Can you explain?

jasnell force-pushed the abortsignal-timeout branch 2 times, most recently from a8362d8 to f04a7fb Compare November 21, 2021 15:31
jasnell added the abortcontroller Issues and PRs related to the AbortController API label Nov 21, 2021

Copy link
Copy Markdown
Member

I don't understand. This sets the reason to a TimeoutError whose stack clearly shows it coming from an AbortSignal. And the code still has to be written to use the reason, which is optional. Can you explain?

Yes, if I have code that might cancel because of a timeout or any other cancellation before .reason I could just check err.name === 'AbortError' which was the consensus reached last time this was discussed.

This method adds a new way to timeout an action that rejects with an error that isn't AbortError. I want to make sure users have a clean way to handle this.

jasnell added the semver-minor PRs that contain new features and should be released in the next minor version. label Nov 21, 2021

jasnell commented Nov 21, 2021

Copy link
Copy Markdown
Member Author

Similar to the AbortSignal.reason, I don't think this actually breaks any patterns. Yes, it sets the reason to the TimeoutError but it's still up to applications to pay attention to that property. Any existing code that handles the abort event that ends up creating and throwing the AbortError instead will continue to work as expected.

This comment has been minimized.

targos left a comment
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

_

Comment thread test/parallel/test-abortcontroller.js Outdated

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Copy Markdown
Collaborator

jasnell commented Nov 25, 2021

Copy link
Copy Markdown
Member Author

@targos ... please take another look. I updated the implementation to ensure that the underlying timer would not prevent the AbortSignal from being garbage collected and to unref the timer object so that the timer would not keep the event loop from exiting.

jasnell force-pushed the abortsignal-timeout branch from cf9cb71 to ed3f0f9 Compare November 25, 2021 18:25

targos commented Nov 25, 2021

Copy link
Copy Markdown
Member

I'll have a look tomorrow.

Copy link
Copy Markdown
Collaborator

Signed-off-by: James M Snell <jasnell@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

abortcontroller Issues and PRs related to the AbortController API author ready PRs that have at least one approval, no outstanding review comments, and a CI started. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants


Back | FazBrowse Home | New Git URL