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

Function basic

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

Source from the content-addressed store, hash-verified

10} = require('internal/event_target');
11
12async function basic() {
13 const ee = new EventEmitter();
14 process.nextTick(() => {
15 ee.emit('foo', 'bar');
16 // 'bar' is a spurious event, we are testing
17 // that it does not show up in the iterable
18 ee.emit('bar', 24);
19 ee.emit('foo', 42);
20 });
21
22 const iterable = on(ee, 'foo');
23
24 const expected = [['bar'], [42]];
25
26 for await (const event of iterable) {
27 const current = expected.shift();
28
29 assert.deepStrictEqual(current, event);
30
31 if (expected.length === 0) {
32 break;
33 }
34 }
35 assert.strictEqual(ee.listenerCount('foo'), 0);
36 assert.strictEqual(ee.listenerCount('error'), 0);
37}
38
39async function invalidArgType() {
40 assert.throws(() => on({}, 'foo'), common.expectsError({

Callers

nothing calls this directly

Calls 4

listenerCountMethod · 0.80
onFunction · 0.50
emitMethod · 0.45
shiftMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…