this.store.subscribe(() => {
   this.events.emit(STATE_UPDATED_EVENT)
   this.getSharedState().then(sharedState => {
     fn(sharedState)
   })
 })
Example #2
0
 watcher.on('added', f=>{
     e.emit('data-updated', f);
 });
Example #3
0
 watcher.on('changed', f=>{
     e.emit('dep-updated', f);
 });
 setTimeout(() => emitter.emit('error', 'bad write error thing'), 10);
Example #5
0
        result = events.EventEmitter.listenerCount(emitter, event); // deprecated

        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);
        result = emitter.emit(event, any, any, any);
    }

    {
        let result: Array<string | symbol>;

        result = emitter.eventNames();
    }

    {
        class Networker extends events.EventEmitter {
            constructor() {
                super();
Example #6
0
 zoneA.run(() => {
   emitter.once('test', shouldNotRun);
   emitter.removeListener('test', shouldNotRun);
   emitter.emit('test');
 });
Example #7
0
 zoneB.run(() => {
   emitter.removeListener('test2', shouldNotRun);
   emitter.emit('test', 'test value');
   emitter.emit('test2', 'test value');
 });
 arr_emitter.forEach((emitter: EventEmitter) => {
     emitter.emit(eventName);
 });
import { EventEmitter } from 'events'

import eventToPromise = require('event-to-promise');

{
	const ee = new EventEmitter()
	const ep = eventToPromise(ee, 'custom')

	ep.then(console.log)
	ee.emit('custom')
}

{
	const et = new EventTarget()
	const tp = eventToPromise.multi(et, ['custom'])

	tp.then(console.log)
	et.dispatchEvent(new Event('custom'))
}
Example #10
0
 function onMessage(message: messageFactory.Message): void {
   const responder = new Responder(config, message);
   responder.channelManager = channelManager;
   emitter.emit("responder", responder);
 }
Example #11
0
export function emit(eventType: string, val?: any) {
  Logger.debug(`Emitting event ${eventType}`);
  return emmitter.emit(eventType, val);
}
Example #12
0
 connect: jest.fn(() => {
   emitter.emit("connect");
 })
 diagnosticsWorker.on('message', (msg: TranspileWorkerMessage) => {
   workerEvent.emit('DiagnosticsWorkerDone');
 });
 diagnosticsWorker.on('error', (err: any) => {
   Logger.error(`diagnosticsWorker error, pid: ${diagnosticsWorker.pid}, error: ${err}`);
   workerEvent.emit('DiagnosticsWorkerDone');
 });
Example #15
0
async function updateSingleProjectEndpoint(
  config: GraphQLProjectConfig | undefined,
  endpoint: GraphQLEndpoint,
  endpointName: string,
  argv: Arguments,
): Promise<void> {
  log(`Downloading introspection from ${chalk.blue(endpoint.url)}`)
  let newSchemaResult
  try {
    newSchemaResult = argv.json
      ? await endpoint.resolveIntrospection()
      : await endpoint.resolveSchema()

    // Do not save an invalid schema
    const clientSchema = argv.json
      ? buildClientSchema(newSchemaResult)
      : newSchemaResult
    const errors = validateSchema(clientSchema)
    if (errors.length > 0) {
      console.error(chalk.red(`${os.EOL}GraphQL endpoint generated invalid schema: ${errors}`))
      setTimeout(() => {
        process.exit(1)
      }, 500)
      return
    }
  } catch (err) {
    emitter.emit('warning', err.message)
    return
  }

  let oldSchema: string | undefined
  if (!argv.console) {
    try {
      oldSchema = argv.output
        ? fs.readFileSync(argv.output, 'utf-8')
        : config!.getSchemaSDL()
    } catch (e) {
      // ignore error if no previous schema file existed
      if (e.message === 'Unsupported schema file extention. Only ".graphql" and ".json" are supported') {
        console.error(e.message)
        setTimeout(() => {
          process.exit(1)
        }, 500)
      }
      // TODO: Add other non-blocking errors to this list
      if (e.message.toLowerCase().indexOf('syntax error') > -1) {
        console.log(`${os.EOL}Ignoring existing schema because it is invalid: ${chalk.red(e.message)}`)
      } else if (e.code !== 'ENOENT') {
        throw e
      }
    }

    if (oldSchema) {
      const newSchema = argv.json
        ? JSON.stringify(newSchemaResult, null, 2)
        : printSchema(newSchemaResult as GraphQLSchema)
      if (newSchema === oldSchema) {
        log(
          chalk.green(
            `${
              config && config.projectName && config.projectName !== 'unnamed'
                ? `project ${chalk.blue(config.projectName)} - `
                : ''
            }${
              endpointName && endpointName !== 'unnamed'
                ? `endpoint ${chalk.blue(endpointName)} - `
                : ''
            }No changes`,
          ),
        )
        emitter.emit('checked')
        return
      }
    }
  }

  let schemaPath = argv.output
  if (argv.console) {
    console.log(
      argv.json
        ? JSON.stringify(newSchemaResult, null, 2)
        : printSchema(newSchemaResult as GraphQLSchema),
    )
  } else if (argv.json) {
    if (!fs.existsSync(schemaPath)) {
      mkdirp.sync(dirname(schemaPath))
    }
    fs.writeFileSync(argv.output, JSON.stringify(newSchemaResult, null, 2))
  } else {
    schemaPath = schemaPath || config!.schemaPath
    if (!fs.existsSync(schemaPath)) {
      mkdirp.sync(dirname(schemaPath))
    }
    await writeSchema(schemaPath as string, newSchemaResult as GraphQLSchema, {
      source: endpoint.url,
      timestamp: new Date().toString(),
    })
  }

  if (schemaPath) {
    log(
      chalk.green(
        `${
          config && config.projectName && config.projectName !== 'unnamed'
            ? `project ${chalk.blue(config.projectName)} - `
            : ''
        }${
          endpointName && endpointName !== 'unnamed'
            ? `endpoint ${chalk.blue(endpointName)} - `
            : ''
        }Schema file was ${oldSchema ? 'updated' : 'created'}: ${chalk.blue(
          relative(process.cwd(), schemaPath),
        )}`,
      ),
    )
  }
  emitter.emit('checked')
}
Example #16
0
 process.nextTick(() => {
   emitter.emit(Request.EVENT_DATA, JSON.stringify(payload));
   emitter.emit(Request.EVENT_END);
 });
Example #17
0
 zoneA.run(() => {
   emitter.once('test', expectZoneA);
   emitter.emit('test', 'test value');
   expect(emitter.listeners('test').length).toEqual(0);
 });
Example #18
0
 process.nextTick(() => {
   emitter.emit(Request.EVENT_DATA, 'definitely_not_json');
   emitter.emit(Request.EVENT_END);
 });
Example #19
0
 zoneB.run(() => emitter.emit('test', 'test value'));
Example #20
0
 process.nextTick(() => {
   emitter.emit(Request.EVENT_DATA, 'a'.repeat(1e6 + 1)); //this may be a fairly intensive test, not sure
                                              // about the impact
 });
 .add("EventEmitter", () => {
     const event = events[seq % events.length];
     const arg = objects[seq++ % events.length];
     eventEmitter.emit(event, arg);
 })
Example #22
0
 stop() {
   this.reset()
   this.events.emit('stop')
 }
 .then(() => this.jobEventEmitter.emit("job.existing.done"));
setTimeout(() => {
  console.log('\n');
  emitter.emit('send');
  emitter.removeListener('send', listener2);
}, 2000);
Example #25
0
 watcher.on('deleted', f=>{
     e.emit('removed', f);
 });
setTimeout(() => {
  console.log('\n');
  emitter.emit('send', 'params1');
  emitter.removeAllListeners('send');
}, 3000);
Example #27
0
 watcher.on('deleted', f=>{
     e.emit('dep-updated', f);
 });
setTimeout(() => {
  console.log('\n');
  emitter.emit(1);
  emitter.emit('send');
}, 3000);
Example #29
0
				it("is called when device reports data", (done: mocha.Done) => {
					attachDeviceLogDataVerificationHandler(deviceInstance.deviceInfo.identifier, done);
					devicesService.emit(DeviceDiscoveryEventNames.DEVICE_FOUND, deviceInstance);
					deviceLogProvider.emit("data", deviceInstance.deviceInfo.identifier, expectedDeviceLogData);
				});
Example #30
0
 emitter.on(when, (data : any) => {
   if(condition()){
     emitter.emit(then, data);
   }
 });