Socket
Socket
Sign inDemoInstall

queue-event-emitter

Package Overview
Dependencies
1
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    queue-event-emitter

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


Version published
Weekly downloads
297
decreased by-16.81%
Maintainers
1
Install size
32.8 kB
Created
Weekly downloads
 

Readme

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

Last updated on 11 Aug 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc