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

events: allow use of AbortController with once #34911

Closed
wants to merge 1 commit into from

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Aug 24, 2020

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 nodejs-github-bot added the events Issues and PRs related to the events subsystem / EventEmitter. label Aug 24, 2020
@jasnell 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 github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 24, 2020
@nodejs-github-bot

This comment has been minimized.

lib/events.js Outdated Show resolved Hide resolved
lib/events.js Outdated Show resolved Hide resolved
lib/events.js Outdated Show resolved Hide resolved
test/parallel/test-events-once.js Show resolved Hide resolved
@jasnell jasnell added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 24, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 24, 2020
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot
Copy link
Collaborator

lib/events.js Outdated Show resolved Hide resolved
lib/events.js Outdated Show resolved Hide resolved
lib/internal/validators.js Outdated Show resolved Hide resolved
test/parallel/test-events-once.js Show resolved Hide resolved
@benjamingr
Copy link
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
Copy link
Member Author

jasnell commented Aug 25, 2020

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).

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

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

Signed-off-by: James M Snell <[email protected]>
@jasnell jasnell added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 27, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 27, 2020
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot
Copy link
Collaborator

lib/events.js Show resolved Hide resolved
lib/events.js Show resolved Hide resolved
@nodejs-github-bot
Copy link
Collaborator

@jasnell jasnell added the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 31, 2020
@github-actions github-actions bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 31, 2020
@github-actions
Copy link
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 <[email protected]>

PR-URL: #34911
Reviewed-By: Denys Otrishko <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
@richardlau
Copy link
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 24, 2021
Allows an AbortSignal to be passed in to events.once() to cancel
waiting on an event.

Signed-off-by: James M Snell <[email protected]>

PR-URL: nodejs#34911
Reviewed-By: Denys Otrishko <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
targos pushed a commit to targos/node that referenced this pull request Apr 26, 2021
Allows an AbortSignal to be passed in to events.once() to cancel
waiting on an event.

Signed-off-by: James M Snell <[email protected]>

PR-URL: nodejs#34911
Reviewed-By: Denys Otrishko <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
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 <[email protected]>

PR-URL: nodejs#34911
Reviewed-By: Denys Otrishko <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
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 <[email protected]>

PR-URL: #34911
Backport-PR-URL: #38386
Reviewed-By: Denys Otrishko <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
@danielleadams danielleadams mentioned this pull request May 3, 2021
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