MCPcopy Create free account
hub / github.com/nodejs/node / catchesErrorsWithAbortSignal

Function catchesErrorsWithAbortSignal

test/parallel/test-events-once.js:61–85  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

59}
60
61async function catchesErrorsWithAbortSignal() {
62 const ee = new EventEmitter();
63 const ac = new AbortController();
64 const signal = ac.signal;
65
66 const expected = new Error('boom');
67 let err;
68 process.nextTick(() => {
69 ee.emit('error', expected);
70 });
71
72 try {
73 const promise = once(ee, 'myevent', { signal });
74 assert.strictEqual(ee.listenerCount('error'), 1);
75 assert.strictEqual(listenerCount(signal, 'abort'), 1);
76
77 await promise;
78 } catch (e) {
79 err = e;
80 }
81 assert.strictEqual(err, expected);
82 assert.strictEqual(ee.listenerCount('error'), 0);
83 assert.strictEqual(ee.listenerCount('myevent'), 0);
84 assert.strictEqual(listenerCount(signal, 'abort'), 0);
85}
86
87async function stopListeningAfterCatchingError() {
88 const ee = new EventEmitter();

Callers 1

Calls 4

listenerCountFunction · 0.85
listenerCountMethod · 0.80
onceFunction · 0.70
emitMethod · 0.45

Tested by

no test coverage detected