File tree 1 file changed +21
-2
lines changed
1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -829,7 +829,7 @@ added: v11.13.0
829
829
* Returns: {Promise}
830
830
831
831
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 .
833
833
The ` Promise ` will resolve with an array of all the arguments emitted to the
834
834
given event.
835
835
@@ -865,7 +865,26 @@ async function run() {
865
865
run ();
866
866
```
867
867
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 `
869
888
<!-- YAML
870
889
added: v12.16.0
871
890
-->
You can’t perform that action at this time.
0 commit comments