Example #1
0
emitter.once('send', listener);

emitter.once(1, listener4);

emitter.prependListener('send', listener5);

emitter.prependOnceListener('send', listener6);

emitter.listeners('send');
emitter.listenerCount('send');
emitter.rawListeners('send');

EventEmitter.defaultMaxListeners = 100;
console.log(`count(static): ${EventEmitter.listenerCount(emitter, 'send')}`);
console.log(`ncount: ${emitter.listenerCount('send')}`);
console.log(`maxListeners: ${emitter.getMaxListeners()}`);
console.log(`eventNames: ${emitter.eventNames().join(', ')}`);
console.log(`rawListeners count: ${emitter.rawListeners('send').length}`);

setTimeout(() => {
  console.log('\n');
  emitter.emit('send');
}, 1000);

setTimeout(() => {
  console.log('\n');
  emitter.emit('send');
  emitter.removeListener('send', listener2);
}, 2000);

setTimeout(() => {
Example #2
0
    result = emitter.removeListener(event, listener);
    result = emitter.off(event, listener);
    result = emitter.removeAllListeners();
    result = emitter.removeAllListeners(event);
    result = emitter.setMaxListeners(42);
}

{
    let result: number;

    result = events.EventEmitter.defaultMaxListeners;
    result = events.EventEmitter.listenerCount(emitter, event); // deprecated

    const promise: Promise<any> = events.once(new events.EventEmitter(), 'error');

    result = emitter.getMaxListeners();
    result = emitter.listenerCount(event);
}

{
    let result: Function[];

    result = emitter.listeners(event);
}

{
    let result: boolean;

    result = emitter.emit(event);
    result = emitter.emit(event, any);
    result = emitter.emit(event, any, any);