3 [![NPM version][npm-image]][npm-url]
4 [![Build status][travis-image]][travis-url]
5 [![Test coverage][coveralls-image]][coveralls-url]
6 [![License][license-image]][license-url]
7 [![Downloads][downloads-image]][downloads-url]
8 [![Gittip][gittip-image]][gittip-url]
10 Get the first event in a set of event emitters and event pairs,
11 then clean up after itself.
16 $ npm install ee-first
22 var first = require('ee-first')
25 ### first(arr, listener)
27 Invoke `listener` on the first event from the list specified in `arr`. `arr` is
28 an array of arrays, with each array in the format `[ee, ...event]`. `listener`
29 will be called only once, the first time any of the given events are emitted. If
30 `error` is one of the listened events, then if that fires first, the `listener`
31 will be given the `err` argument.
33 The `listener` is invoked as `listener(err, ee, event, args)`, where `err` is the
34 first argument emitted from an `error` event, if applicable; `ee` is the event
35 emitter that fired; `event` is the string event name that fired; and `args` is an
36 array of the arguments that were emitted on the event.
39 var ee1 = new EventEmitter()
40 var ee2 = new EventEmitter()
43 [ee1, 'close', 'end', 'error'],
45 ], function (err, ee, event, args) {
52 The group of listeners can be cancelled before being invoked and have all the event
53 listeners removed from the underlying event emitters.
57 [ee1, 'close', 'end', 'error'],
59 ], function (err, ee, event, args) {
63 // cancel and clean up
67 [npm-image]: https://img.shields.io/npm/v/ee-first.svg?style=flat-square
68 [npm-url]: https://npmjs.org/package/ee-first
69 [github-tag]: http://img.shields.io/github/tag/jonathanong/ee-first.svg?style=flat-square
70 [github-url]: https://github.com/jonathanong/ee-first/tags
71 [travis-image]: https://img.shields.io/travis/jonathanong/ee-first.svg?style=flat-square
72 [travis-url]: https://travis-ci.org/jonathanong/ee-first
73 [coveralls-image]: https://img.shields.io/coveralls/jonathanong/ee-first.svg?style=flat-square
74 [coveralls-url]: https://coveralls.io/r/jonathanong/ee-first?branch=master
75 [license-image]: http://img.shields.io/npm/l/ee-first.svg?style=flat-square
76 [license-url]: LICENSE.md
77 [downloads-image]: http://img.shields.io/npm/dm/ee-first.svg?style=flat-square
78 [downloads-url]: https://npmjs.org/package/ee-first
79 [gittip-image]: https://img.shields.io/gittip/jonathanong.svg?style=flat-square
80 [gittip-url]: https://www.gittip.com/jonathanong/