File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Expand file tree Collapse file tree 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
829829* Returns: {Promise}
830830
831831Creates 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 .
833833The ` Promise ` will resolve with an array of all the arguments emitted to the
834834given event.
835835
@@ -865,7 +865,26 @@ async function run() {
865865run ();
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
870889added: v12.16.0
871890-->
You can’t perform that action at this time.
0 commit comments