node-modules/await-first

Name: await-first

Owner: node_modules

Description: Wait the first event in a set of event pairs, then clean up after itself.

Created: 2017-11-23 02:40:57.0

Updated: 2018-01-25 02:23:15.0

Pushed: 2017-11-23 16:10:20.0

Homepage:

Size: 5

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

await-first

Wait the first event in a set of event pairs, then clean up after itself.

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install
m install await-first --save
Example
t EventEmitter = require('events');
t awaitFirst = require('await-first');

c function waitMessageOrClose(ee) {
nst o = await awaitFirst(ee, [ 'message', 'close' ]);

itch (o.event) {
case 'message':
  const msg = o.args[0]; // [ 'hello world' ]
  console.log('new message =>', msg);
  break;
case 'close':
  console.log('closed');
  break;



t ee = new EventEmitter();
MessageOrClose(ee);

imeout(() => {
.emit('message', 'hello world');
000);
t net = require('net');
t awaitFirst = require('await-first');

c function connect() {
nst socket = net.connect(8080, '127.0.0.1');
cket.awaitFirst = awaitFirst;

y {
// wait `connect` or `error` event
await socket.awaitFirst([ 'connect', 'error' ]);
catch (err) {
console.log(err);

 ...


ect();

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.