Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix review findings
  • Loading branch information
Flarna committed Dec 13, 2019
commit 793205c1f13767c004eeaab8fb94b0462d09e86b
6 changes: 3 additions & 3 deletions doc/api/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ by installing a listener using the symbol `errorMonitor`.

```js
const myEmitter = new MyEmitter();
myEmitter.on(errorMonitor, (err) => {
myEmitter.on(EventEmitter.errorMonitor, (err) => {
MyMonitoringTool.log(err);
});
myEmitter.emit('error', new Error('whoops!'));
Expand Down Expand Up @@ -365,11 +365,11 @@ Its `name` property is set to `'MaxListenersExceededWarning'`.
added: REPLACEME
-->

This symbol shall be used to install a listener only monitoring `'error'`
This symbol shall be used to install a listener for only monitoring `'error'`
events. Listeners installed using this symbol are called before the regular
`'error'` listeners are called.

Installing a listener using this symbol does not change the behavior once a
Installing a listener using this symbol does not change the behavior once an
`'error'` event is emitted, therefore the process will still crash if no
regular `'error'` listener is installed.

Expand Down
13 changes: 4 additions & 9 deletions test/parallel/test-event-emitter-error-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const theErr = new Error('MyError');

EE.on(
EventEmitter.errorMonitor,
common.mustCall((e) => assert.strictEqual(e, theErr), 3)
common.mustCall(function onErrorMonitor(e) {
assert.strictEqual(e, theErr);
}, 3)
);

// Verify with no error listener
Expand All @@ -23,14 +25,7 @@ EE.emit('error', theErr);

// Verify it works with once
process.nextTick(() => EE.emit('error', theErr));
async function testOnce() {
try {
await EventEmitter.once(EE, 'notTriggered');
} catch (e) {
assert.strictEqual(e, theErr);
}
}
testOnce();
assert.rejects(EventEmitter.once(EE, 'notTriggered'), theErr);

// Only error events trigger error monitor
EE.on('aEvent', common.mustCall());
Expand Down