Skip to content

Commit 1a362d8

Browse files
Trotttargos
authored andcommitted
doc: revise AbortSignal text and example using events.once()
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: #35005 Backport-PR-URL: #38386 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 3f33b5a commit 1a362d8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

doc/api/events.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -839,8 +839,7 @@ added:
839839
* `emitter` {EventEmitter}
840840
* `name` {string}
841841
* `options` {Object}
842-
* `signal` {AbortSignal} An {AbortSignal} that may be used to cancel waiting
843-
for the event.
842+
* `signal` {AbortSignal} Can be used to cancel waiting for the event.
844843
* Returns: {Promise}
845844

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

902-
An {AbortSignal} may be used to cancel waiting for the event early:
901+
An {AbortSignal} can be used to cancel waiting for the event:
903902

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

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

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

0 commit comments

Comments
 (0)