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

events: allow use of AbortController with once by jasnell · Pull Request #34911 · nodejs/node · GitHub

/ node Public

events: allow use of AbortController with once - #34911

Closed
jasnell wants to merge 1 commit into
nodejs:masterfrom
jasnell:abortable-once
Closed

events: allow use of AbortController with once#34911
jasnell wants to merge 1 commit into
nodejs:masterfrom
jasnell:abortable-once

Conversation

jasnell commented Aug 24, 2020

Copy link
Copy Markdown
Member

Allows an AbortSignal to be passed in to events.once() to cancel
waiting on an event.

const ee = new EventEmitter();
const ac = new AbortController();

const p = events.once(ee, 'foo', { signal: ac.signal });

process.nextTick(() => ac.abort());

// p is rejected with an AbortError
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

nodejs-github-bot added the events Issues and PRs related to the events subsystem / EventEmitter. label Aug 24, 2020
jasnell added semver-minor PRs that contain new features and should be released in the next minor version. request-ci Add this label to start a Jenkins CI on a PR. labels Aug 24, 2020
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 24, 2020

This comment has been minimized.

Comment thread lib/events.js Outdated
Comment thread lib/events.js Outdated
Comment thread lib/events.js Outdated
Comment thread test/parallel/test-events-once.js Outdated
jasnell requested a review from lundibundi August 24, 2020 21:26
jasnell added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 24, 2020
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 24, 2020

This comment has been minimized.

Copy link
Copy Markdown
Collaborator

Comment thread lib/events.js Outdated
Comment thread lib/events.js Outdated
Comment thread lib/internal/validators.js Outdated
Comment thread test/parallel/test-events-once.js Outdated

Copy link
Copy Markdown
Member

The actual code looks good to me - I am not sure what the use case is - to unsubscribe from lots of events with AbortSignal at once?

jasnell commented Aug 25, 2020

Copy link
Copy Markdown
Member Author

Mostly to allow propagation of an AbortSignal through a complex operation. Imagine, for instance, having an async operation that you want to be abortable, and within that is an await on an event or series of events. Currently, there is no way to bail out of that without a potentially destructive action on the emitter (emitting an error).

mcollina left a comment

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

lgtm

Allows an AbortSignal to be passed in to events.once() to cancel
waiting on an event.

Signed-off-by: James M Snell <jasnell@gmail.com>
jasnell added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 27, 2020
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 27, 2020

This comment has been minimized.

Copy link
Copy Markdown
Collaborator

Comment thread lib/events.js
Comment thread lib/events.js

Copy link
Copy Markdown
Collaborator

jasnell added the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 31, 2020
github-actions Bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 31, 2020

Copy link
Copy Markdown
Contributor

Landed in 883fc77

nodejs-github-bot pushed a commit that referenced this pull request Aug 31, 2020
Allows an AbortSignal to be passed in to events.once() to cancel
waiting on an event.

Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: #34911
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>

Copy link
Copy Markdown
Member

Added dont-land labels as this depends on AbortController (#33527) which is semver-major.

targos pushed a commit to targos/node that referenced this pull request Apr 30, 2021
Allows an AbortSignal to be passed in to events.once() to cancel
waiting on an event.

Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: nodejs#34911
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
targos pushed a commit that referenced this pull request Apr 30, 2021
Allows an AbortSignal to be passed in to events.once() to cancel
waiting on an event.

Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: #34911
Backport-PR-URL: #38386
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
danielleadams mentioned this pull request May 3, 2021
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

events Issues and PRs related to the events subsystem / EventEmitter. 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.

7 participants


Back | FazBrowse Home | New Git URL