You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

ee-first

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

ee-first

return the first event in a set of ee/event pairs


Version published
Maintainers
2
Created

Package description

What is ee-first?

The ee-first package is a utility for Node.js that allows you to wait for multiple EventEmitter or Stream instances to emit an event or error and then execute a callback. It is particularly useful when you need to listen for an event from multiple sources and want to take action only after the first one occurs.

What are ee-first's main functionalities?

Listening for the first event or error from multiple emitters

This feature allows you to pass an array of arrays, where each sub-array contains an EventEmitter instance followed by one or more event names. The callback function is then executed when the first event from any of the listed emitters is emitted.

const first = require('ee-first');

const stream1 = getSomeReadableStream();
const stream2 = getAnotherReadableStream();

const thunk = first([
  [stream1, 'end', 'error'],
  [stream2, 'end', 'error']
], function (err, ee, event, args) {
  // This function will be called when one of the streams emits 'end' or 'error'
  // `ee` is the event emitter that fired
  // `event` is the string name of the event that fired
  // `args` is an array of the arguments that were passed to the event
});

Other packages similar to ee-first

Readme

Source

EE First

NPM version Build status Test coverage License Downloads Gittip

Get the first event in a set of event emitters and event pairs, then clean up after itself.

Install

$ npm install ee-first

API

var first = require('ee-first')

first(arr, listener)

Invoke listener on the first event from the list specified in arr. arr is an array of arrays, with each array in the format [ee, ...event]. listener will be called only once, the first time any of the given events are emitted. If error is one of the listened events, then if that fires first, the listener will be given the err argument.

The listener is invoked as listener(err, ee, event, args), where err is the first argument emitted from an error event, if applicable; ee is the event emitter that fired; event is the string event name that fired; and args is an array of the arguments that were emitted on the event.

var ee1 = new EventEmitter()
var ee2 = new EventEmitter()

first([
  [ee1, 'close', 'end', 'error'],
  [ee2, 'error']
], function (err, ee, event, args) {
  // listener invoked
})
.cancel()

The group of listeners can be cancelled before being invoked and have all the event listeners removed from the underlying event emitters.

var thunk = first([
  [ee1, 'close', 'end', 'error'],
  [ee2, 'error']
], function (err, ee, event, args) {
  // listener invoked
})

// cancel and clean up
thunk.cancel()

FAQs

Package last updated on 25 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc