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
Size: 5
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Wait the first event in a set of event pairs, then clean up after itself.
m install await-first --save
awaitFirst(ee, events)
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);
obj.awaitFirst(events)
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();