File tree 1 file changed +20
-1
lines changed
1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -837,7 +837,7 @@ added:
837
837
* Returns: {Promise}
838
838
839
839
Creates a ` Promise ` that is fulfilled when the ` EventEmitter ` emits the given
840
- event or that is rejected when the ` EventEmitter ` emits ` 'error' ` .
840
+ event or that is rejected if the ` EventEmitter ` emits ` 'error' ` while waiting .
841
841
The ` Promise ` will resolve with an array of all the arguments emitted to the
842
842
given event.
843
843
@@ -873,6 +873,25 @@ async function run() {
873
873
run ();
874
874
```
875
875
876
+ The special handling of the ` 'error' ` event is only used when ` events.once() `
877
+ is used to wait for another event. If ` events.once() ` is used to wait for the
878
+ '` error' ` event itself, then it is treated as any other kind of event without
879
+ special handling:
880
+
881
+ ``` js
882
+ const { EventEmitter , once } = require (' events' );
883
+
884
+ const ee = new EventEmitter ();
885
+
886
+ once (ee, ' error' )
887
+ .then (([err ]) => console .log (' ok' , err .message ))
888
+ .catch ((err ) => console .log (' error' , err .message ));
889
+
890
+ ee .emit (' error' , new Error (' boom' ));
891
+
892
+ // Prints: ok boom
893
+ ```
894
+
876
895
## ` events.captureRejections `
877
896
<!-- YAML
878
897
added:
You can’t perform that action at this time.
0 commit comments