MCPcopy Index your code
hub / github.com/nodejs/node / abortableOnAfterDone

Function abortableOnAfterDone

test/parallel/test-events-on-async-iterator.js:355–374  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

353}
354
355async function abortableOnAfterDone() {
356 const ee = new EventEmitter();
357 const ac = new AbortController();
358
359 const i = setInterval(() => ee.emit('foo', 'foo'), 1);
360 let count = 0;
361
362 async function foo() {
363 for await (const f of on(ee, 'foo', { signal: ac.signal })) {
364 assert.strictEqual(f[0], 'foo');
365 if (++count === 5)
366 break;
367 }
368 ac.abort(); // No error will occur
369 }
370
371 foo().finally(() => {
372 clearInterval(i);
373 });
374}
375
376async function abortListenerRemovedAfterComplete() {
377 const ee = new EventEmitter();

Callers

nothing calls this directly

Calls 4

clearIntervalFunction · 0.85
fooFunction · 0.70
setIntervalFunction · 0.50
emitMethod · 0.45

Tested by

no test coverage detected