0.3.0 • Published 6 years ago

event-n-times v0.3.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

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