Skip to content

Commit

Permalink
doc: revise AbortSignal text and example using events.once()
Browse files Browse the repository at this point in the history
Add a line to the example code to clarify what happens if an event is
emitted after listening is canceled. Make minor revisions to surrounding
text.

PR-URL: nodejs#35005
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
Trott authored and targos committed Apr 26, 2021
1 parent 7cfb6bd commit 5f9c809
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions doc/api/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -839,8 +839,7 @@ added:
* `emitter` {EventEmitter}
* `name` {string}
* `options` {Object}
* `signal` {AbortSignal} An {AbortSignal} that may be used to cancel waiting
for the event.
* `signal` {AbortSignal} Can be used to cancel waiting for the event.
* Returns: {Promise}

Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given
Expand Down Expand Up @@ -899,7 +898,7 @@ ee.emit('error', new Error('boom'));
// Prints: ok boom
```

An {AbortSignal} may be used to cancel waiting for the event early:
An {AbortSignal} can be used to cancel waiting for the event:

```js
const { EventEmitter, once } = require('events');
Expand All @@ -922,6 +921,7 @@ async function foo(emitter, event, signal) {

foo(ee, 'foo', ac.signal);
ac.abort(); // Abort waiting for the event
ee.emit('foo'); // Prints: Waiting for the event was canceled!
```

### Awaiting multiple events emitted on `process.nextTick()`
Expand Down

0 comments on commit 5f9c809

Please sign in to comment.