Skip to content

Commit f9c362f

Browse files
committed
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 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 69b8a39 commit f9c362f

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
@@ -835,8 +835,7 @@ added:
835835
* `emitter` {EventEmitter}
836836
* `name` {string}
837837
* `options` {Object}
838-
* `signal` {AbortSignal} An {AbortSignal} that may be used to cancel waiting
839-
for the event.
838+
* `signal` {AbortSignal} Can be used to cancel waiting for the event.
840839
* Returns: {Promise}
841840

842841
Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given
@@ -895,7 +894,7 @@ ee.emit('error', new Error('boom'));
895894
// Prints: ok boom
896895
```
897896

898-
An {AbortSignal} may be used to cancel waiting for the event early:
897+
An {AbortSignal} can be used to cancel waiting for the event:
899898

900899
```js
901900
const { EventEmitter, once } = require('events');
@@ -918,6 +917,7 @@ async function foo(emitter, event, signal) {
918917

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

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

0 commit comments

Comments
 (0)