Example #1
0
  return new Promise<any>((resolve, reject) => {
    emitter.once(event, (value: any) => {
      resolve(value);
    });

    emitter.once('error', (err: Error) => {
      reject(err);
    });
  });
Example #2
0
 dummySocket.once('testing', data => {
   assert.deepStrictEqual(data, data1);
   dummySocket.once('testing', result => {
     assert.deepStrictEqual(result, data2);
     done();
   });
 });
 this.getSharedState().then(sharedState => {
   let isUnlocked = !sharedState.isLocked && sharedState.didInit
   if (isUnlocked) {
     fn()
   } else {
     this.events.once(STATE_UPDATED_EVENT, tryCall)
   }
 })
Example #4
0
      it('dispatches a basic event', done => {
        dummySocket.once('testing', data => {
          assert.strictEqual(data, 'hi');
          done();
        });

        dispatcher('testing', dummyChannel, dummyHook);
      });
Example #5
0
      it('dispatches event on a hooks path event', done => {
        dummyHook.path = 'myservice';

        dummySocket.once('myservice testing', data => {
          assert.strictEqual(data, 'hi');
          done();
        });

        dispatcher('testing', dummyChannel, dummyHook);
      });
 const tryResolve = () => {
   if (resolved) {
     return
   }
   if (this._events.length >= count) {
     resolved = true
     resolve()
     return
   }
   this._monitor.once('event', tryResolve)
 }
Example #7
0
      it('dispatches `hook.dispatch` instead', done => {
        const message = 'hi from dispatch';

        dummyHook.dispatch = message;

        dummySocket.once('testing', data => {
          assert.strictEqual(data, message);
          done();
        });

        dispatcher('testing', dummyChannel, dummyHook);
      });
Example #8
0
 function wait(cb: Function): void {
   function fail() : void {
     obj.removeListener(event, handler);
     cb("timeout");
   }
   const timer = setTimeout(fail, timeout_ms);
   function handler(...args): void {
     clearTimeout(timer);
     val = args;
     cb();
   }
   obj.once(event, handler);
 }
Example #9
0
      it('dispatches arrays properly for custom events', done => {
        const result = [
          { message: 'First' },
          { message: 'Second' }
        ];

        dummyHook.result = result;

        dummySocket.once('otherEvent', data => {
          assert.deepStrictEqual(data, result);
          done();
        });

        dispatcher('otherEvent', dummyChannel, dummyHook, result);
      });
Example #10
0
      it('dispatches arrays properly hook events', done => {
        const data1 = { message: 'First message' };
        const data2 = { message: 'Second message' };

        dummyHook.result = [ data1, data2 ];

        dummySocket.once('testing', data => {
          assert.deepStrictEqual(data, data1);
          dummySocket.once('testing', result => {
            assert.deepStrictEqual(result, data2);
            done();
          });
        });

        dispatcher('testing', dummyChannel, dummyHook, data1);
        dispatcher('testing', dummyChannel, dummyHook, data2);
      });
Example #11
0
const listener5 = () => {
  console.log('prepend listener');
};
const listener6 = () => {
  console.log('prepend once listener');
};

emitter.setMaxListeners(100);

emitter.addListener('send', listener1);

emitter.on('send', listener2);

emitter.on('send', listener3);

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()}`);
Example #12
0
 function wait(cb: Function): void {
   obj.once(event, function(...args): void {
     val = args;
     cb();
   });
 }
Example #13
0
import * as events from 'events';

const emitter: events.EventEmitter = new events.EventEmitter();
const event: string | symbol = '';
const listener: (...args: any[]) => void = () => {};
const any: any = 1;

{
    let result: events.EventEmitter;

    result = emitter.addListener(event, listener);
    result = emitter.on(event, listener);
    result = emitter.once(event, listener);
    result = emitter.prependListener(event, listener);
    result = emitter.prependOnceListener(event, listener);
    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();
Example #14
0
 zoneA.run(() => {
   emitter.once('test', shouldNotRun);
   emitter.removeListener('test', shouldNotRun);
   emitter.emit('test');
 });
Example #15
0
 zoneA.run(() => {
   emitter.once('test', expectZoneA);
   emitter.emit('test', 'test value');
   expect(emitter.listeners('test').length).toEqual(0);
 });