NeXTSTEP Programming Mastermind
Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

event-n-times

0.3.0 • Public • Published

event-n-times

build status AppVeyor Build Status


Register event handlers with a max cap.


Get it!

npm install --save event-n-times

Usage

var nify = require('event-n-times')
var passthru = require('stream').PassThrough()
 
passthru = nify(passthru)
 
passthru.ntimes('data', 2, function (chunk) {
  console.log(chunk.toString())
})
 
for (var i = 0; i < 7; i++) passthru.write(Buffer.from('fraud'))

API

emitter = nify(emitter)

Add a .ntimes instance method on the emitter.

emitter.ntimes(eventName, n, listener)

Register an event handler that will be called at most n times.

Alias: emitter.addNtimeListener(eventName, n, listener)

emitter.prependNtimeListener(eventName, n, listener)

Register a n-time handler via emitter.prependListener.


License

MIT

Install

npm i event-n-times

DownloadsWeekly Downloads

2

Version

0.3.0

License

MIT

Unpacked Size

7.65 kB

Total Files

10

Last publish

Collaborators

  • avatar