Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a9f0fc9

Browse filesBrowse files
jasnelladdaleax
authored andcommitted
doc: document behavior for once(ee, 'error')
Fixes: #31244 PR-URL: #34225 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent ed055c0 commit a9f0fc9
Copy full SHA for a9f0fc9

File tree

Expand file treeCollapse file tree

1 file changed

+21
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+21
-2
lines changed
Open diff view settings
Collapse file

‎doc/api/events.md‎

Copy file name to clipboardExpand all lines: doc/api/events.md
+21-2Lines changed: 21 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ added: v11.13.0
829829
* Returns: {Promise}
830830

831831
Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given
832-
event or that is rejected when the `EventEmitter` emits `'error'`.
832+
event or that is rejected if the `EventEmitter` emits `'error'` while waiting.
833833
The `Promise` will resolve with an array of all the arguments emitted to the
834834
given event.
835835

@@ -865,7 +865,26 @@ async function run() {
865865
run();
866866
```
867867

868-
## events.captureRejections
868+
The special handling of the `'error'` event is only used when `events.once()`
869+
is used to wait for another event. If `events.once()` is used to wait for the
870+
'`error'` event itself, then it is treated as any other kind of event without
871+
special handling:
872+
873+
```js
874+
const { EventEmitter, once } = require('events');
875+
876+
const ee = new EventEmitter();
877+
878+
once(ee, 'error')
879+
.then(([err]) => console.log('ok', err.message))
880+
.catch((err) => console.log('error', err.message));
881+
882+
ee.emit('error', new Error('boom'));
883+
884+
// Prints: ok boom
885+
```
886+
887+
## `events.captureRejections`
869888
<!-- YAML
870889
added: v12.16.0
871890
-->

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.