mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
doc: document behavior for once(ee, 'error')
Fixes: https://github.com/nodejs/node/issues/31244 PR-URL: https://github.com/nodejs/node/pull/34225 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
1 parent
ed055c010d
commit
a9f0fc9896
1 file changed
+21
-2
+21
-2
@@ -829,7 +829,7 @@ added: v11.13.0
|
||||
* Returns: {Promise}
|
||||
|
||||
Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given
|
||||
event or that is rejected when the `EventEmitter` emits `'error'`.
|
||||
event or that is rejected if the `EventEmitter` emits `'error'` while waiting.
|
||||
The `Promise` will resolve with an array of all the arguments emitted to the
|
||||
given event.
|
||||
|
||||
@@ -865,7 +865,26 @@ async function run() {
|
||||
run();
|
||||
```
|
||||
|
||||
## events.captureRejections
|
||||
The special handling of the `'error'` event is only used when `events.once()`
|
||||
is used to wait for another event. If `events.once()` is used to wait for the
|
||||
'`error'` event itself, then it is treated as any other kind of event without
|
||||
special handling:
|
||||
|
||||
```js
|
||||
const { EventEmitter, once } = require('events');
|
||||
|
||||
const ee = new EventEmitter();
|
||||
|
||||
once(ee, 'error')
|
||||
.then(([err]) => console.log('ok', err.message))
|
||||
.catch((err) => console.log('error', err.message));
|
||||
|
||||
ee.emit('error', new Error('boom'));
|
||||
|
||||
// Prints: ok boom
|
||||
```
|
||||
|
||||
## `events.captureRejections`
|
||||
<!-- YAML
|
||||
added: v12.16.0
|
||||
-->
|
||||
|
||||
Reference in new issue
Block a user