Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

queue-event-emitter

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

queue-event-emitter

Simple `EventEmitter` which runs every event handler in a queue

  • 2.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
222
increased by7.77%
Maintainers
1
Weekly downloads
 
Created
Source

queue-event-emitter

npm version build status

QueueEventEmitter is a simple EventEmitter which runs every event handler in a queue.

Installation

npm i --save queue-event-emitter

Usage

const QueueEventEmitter = require('queue-event-emitter')

// helper function
const sleep = (time) => (
  new Promise((resolve) => setTimeout(resolve, time))
)

// event emitter
const emitter = new QueueEventEmitter()

// event handlers, should return promise
emitter.on('first', async (data) => {
  await sleep(3000)
  console.log('data:', data)
})
emitter.on('second', async (data) => {
  await sleep(1000)
  console.log('data:', data)
})
emitter.on('third', async (data) => {
  await sleep(10)
  console.log('data:', data)
})

// send events
emitter.emit('first', 10)
emitter.emit('second', 20)
emitter.emit('third', 30)
emitter.emit('first', 40)
emitter.emit('third', 50)
emitter.emit('third', 60)
emitter.emit('second', 70)

// result in console will be
// data: 10
// data: 20
// data: 30
// data: 40
// data: 50
// data: 60
// data: 70

API

Implements the same api as node's EventEmitter.

Options

QueueEventEmitter class accepts following options:

  • options.concurrency <number> The maximum number of events to execute at once. (Default: 1)

Licence

Licensed under MIT

Keywords

FAQs

Package last updated on 11 Aug 2018

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc