How to use the events.once function in events

To help you get started, we’ve selected a few events examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alexbosworth / ln-service / test / routerrpc-integration / test_subscribe_to_probe.js View on Github external
const {channels} = await getChannels({lnd: cluster.remote.lnd});

  const invoice = await createInvoice({tokens, lnd: cluster.remote.lnd});

  await delay(1000);

  const sub = subscribeToProbe({
    lnd,
    destination: cluster.remote_node_public_key,
    tokens: invoice.tokens,
  });

  sub.on('error', () => {});

  const [{route}] = await once(sub, 'probing');

  // On 0.7.1 confidence is not supported
  delete route.confidence;

  deepIs(route, {
    fee: 1,
    fee_mtokens: '1500',
    hops: [
      {
        channel: controlToTargetChan.id,
        channel_capacity: controlToTargetChan.capacity,
        fee: 1,
        fee_mtokens: '1500',
        forward: tokens,
        forward_mtokens: `${tokens}000`,
        public_key: cluster.target_node_public_key,
github graalvm / graaljs / test / parallel / test-events-once.js View on Github external
async function onceAnEvent() {
  const ee = new EventEmitter();

  process.nextTick(() => {
    ee.emit('myevent', 42);
  });

  const [value] = await once(ee, 'myevent');
  strictEqual(value, 42);
  strictEqual(ee.listenerCount('error'), 0);
  strictEqual(ee.listenerCount('myevent'), 0);
}
github graalvm / graaljs / test / parallel / test-events-once.js View on Github external
async function onceError() {
  const ee = new EventEmitter();

  const expected = new Error('kaboom');
  process.nextTick(() => {
    ee.emit('error', expected);
  });

  const [err] = await once(ee, 'error');
  strictEqual(err, expected);
  strictEqual(ee.listenerCount('error'), 0);
  strictEqual(ee.listenerCount('myevent'), 0);
}
github metarhia / metasync / test / fixtures / iterator.js View on Github external
metatests.test('AsyncIterator.throttle', async test => {
  const EXPECTED_DEVIATION = 0.2;

  const pathThrottleFile = path.join(__dirname, './throttle.js');
  const child = fork(pathThrottleFile);

  const [{ sum, actualDeviation, ARRAY_SIZE }] = await once(child, 'message');
  test.strictSame(sum, ARRAY_SIZE);
  test.assert(actualDeviation <= EXPECTED_DEVIATION);
});
github clusterio / factorioClusterio / test / integration / server.js View on Github external
it("should detect factorio hanging on shutdown", async function() {
				slowTest(this);
				log(".start() for hang detection");

				await server.start("test.zip");
				if (!server._rconReady) {
					await events.once(server, 'rcon-ready');
				}
				server.sendRcon("/c while true do end").catch(() => {});
				await new Promise((resolve) => setTimeout(resolve, 300));
				log(".stop() for hang detection");
				await server.stop();
			});
		});
github patr0nus / DeskGap / test / api-tests / async-node.js View on Github external
withWebView(it, 'can require built-in modules', async (win) => {
            const execution = win.webView.executeJavaScript(`
                deskgap.asyncNode.require('os').then(function (os) {
                    return os.invoke('platform').value();
                }).then(function (result) {
                    deskgap.messageUI.send('async-node-result', result);
                })
            `);
            const [, result] = await once(messageNode, 'async-node-result');
            expect(result).to.equal(require('os').platform());
            await execution;
        }, true);
github hyperswarm / network / test / index.js View on Github external
async function dhtBootstrap () {
  const node = dht()
  await once(node, 'listening')
  const { port } = node.address()
  return {
    port,
    bootstrap: [`127.0.0.1:${port}`],
    closeDht: () => node.destroy()
  }
}
github patr0nus / DeskGap / test / api-tests / webview.js View on Github external
withWebView(it, 'loads the given file', async (win) => {
            win.webView.loadFile(path.resolve(__dirname, '..', 'fixtures', 'files', 'web-view-load-file.html'));
            await once(messageNode, 'hello-web-view-load-file');
        })
    });
github graalvm / graaljs / test / parallel / test-readable-from.js View on Github external
async function destroysTheStreamWhenThrowing() {
  async function* generate() {
    throw new Error('kaboom');
  }

  const stream = Readable.from(generate());

  stream.read();

  const [err] = await once(stream, 'error');
  strictEqual(err.message, 'kaboom');
  strictEqual(stream.destroyed, true);

}
github mikeal / reg / src / nodejs / deflate.js View on Github external
const _write = async (stream, chunk) => {
  if (!stream.write(chunk)) await once(stream, 'drain')
}