{"_id":"await-first","_rev":"372187","name":"await-first","description":"Wait the first event in a set of event emitters and event pairs, then clean up after itself.","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"gxcsoccer","email":"gxcsoccer@gmail.com"}],"time":{"modified":"2021-07-27T02:41:07.000Z","created":"2017-11-23T16:10:31.563Z","1.0.0":"2017-11-23T16:10:31.563Z"},"users":{},"author":{"name":"gxcsoccer","email":"gxcsoccer@126.com"},"repository":{"type":"git","url":"git+https://github.com/node-modules/await-first.git"},"versions":{"1.0.0":{"name":"await-first","version":"1.0.0","description":"Wait the first event in a set of event emitters and event pairs, then clean up after itself.","main":"lib/index.js","files":["lib"],"scripts":{"autod":"autod","pkgfiles":"egg-bin pkgfiles --check","test":"npm run lint && npm run test-local","test-local":"egg-bin test","cov":"TEST_TIMEOUT=5000 egg-bin cov","lint":"eslint . --ext .js","ci":"npm run autod -- --check && npm run pkgfiles && npm run lint && npm run cov"},"repository":{"type":"git","url":"git+https://github.com/node-modules/await-first.git"},"keywords":["ee-first","await"],"author":{"name":"gxcsoccer","email":"gxcsoccer@126.com"},"license":"MIT","bugs":{"url":"https://github.com/node-modules/await-first/issues"},"homepage":"https://github.com/node-modules/await-first#readme","dependencies":{"ee-first":"^1.1.1"},"devDependencies":{"autod":"^3.0.1","egg-bin":"^4.3.5","egg-ci":"^1.8.0","eslint":"^4.11.0","eslint-config-egg":"^5.1.1","mm":"^2.2.0"},"ci":{"version":"6, 8, 9"},"engines":{"node":">= 6.0.0"},"gitHead":"4b0becd6d08a3abf7863ec0db5d41c18faa44347","_id":"await-first@1.0.0","_npmVersion":"5.5.1","_nodeVersion":"8.9.1","_npmUser":{"name":"gxcsoccer","email":"gxcsoccer@gmail.com"},"dist":{"shasum":"06afa6db7cebe412be9be54e82dd8c6cb4cdb241","size":2379,"noattachment":false,"key":"/await-first/-/await-first-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/await-first/download/await-first-1.0.0.tgz"},"maintainers":[{"name":"gxcsoccer","email":"gxcsoccer@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/await-first-1.0.0.tgz_1511453431345_0.8586350539699197"},"directories":{},"publish_time":1511453431563,"_hasShrinkwrap":false,"_cnpm_publish_time":1511453431563}},"readme":"# await-first\nWait the first event in a set of event pairs, then clean up after itself.\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![David deps][david-image]][david-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/await-first.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/await-first\n[travis-image]: https://img.shields.io/travis/node-modules/await-first.svg?style=flat-square\n[travis-url]: https://travis-ci.org/node-modules/await-first\n[codecov-image]: https://codecov.io/gh/node-modules/await-first/branch/master/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/node-modules/await-first\n[david-image]: https://img.shields.io/david/node-modules/await-first.svg?style=flat-square\n[david-url]: https://david-dm.org/node-modules/await-first\n[snyk-image]: https://snyk.io/test/npm/await-first/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/await-first\n[download-image]: https://img.shields.io/npm/dm/await-first.svg?style=flat-square\n[download-url]: https://npmjs.org/package/await-first\n\n## Install\n\n```\n$ npm install await-first --save\n```\n\n## Example\n\n- `awaitFirst(ee, events)`\n\n```js\nconst EventEmitter = require('events');\nconst awaitFirst = require('await-first');\n\nasync function waitMessageOrClose(ee) {\n  const o = await awaitFirst(ee, [ 'message', 'close' ]);\n\n  switch (o.event) {\n    case 'message':\n      const msg = o.args[0]; // [ 'hello world' ]\n      console.log('new message =>', msg);\n      break;\n    case 'close':\n      console.log('closed');\n      break;\n  }\n}\n\nconst ee = new EventEmitter();\nwaitMessageOrClose(ee);\n\nsetTimeout(() => {\n  ee.emit('message', 'hello world');\n}, 1000);\n```\n\n- `obj.awaitFirst(events)`\n\n```js\nconst net = require('net');\nconst awaitFirst = require('await-first');\n\nasync function connect() {\n  const socket = net.connect(8080, '127.0.0.1');\n  socket.awaitFirst = awaitFirst;\n\n  try {\n    // wait `connect` or `error` event\n    await socket.awaitFirst([ 'connect', 'error' ]);\n  } catch (err) {\n    console.log(err);\n  }\n  // ...\n}\n\nconnect();\n```","_attachments":{},"homepage":"https://github.com/node-modules/await-first#readme","bugs":{"url":"https://github.com/node-modules/await-first/issues"},"license":"MIT"}