next-event

1.0.0 • Public • Published

next-event

Call a function the next time a specific event is emitted

npm install next-event

build status

Basically like .once but faster.

Usage

var nextEvent = require('next-event')
 
var ontest = nextEvent(emitter, 'test')
 
ontest(function () {
  console.log('i am only called once')
})
 
emitter.emit('test')
emitter.emit('test')

Note that only the last function you pass to ontest in the above example will be called when the next event is emitted

ontest(function () {
  console.log('i am never called')
})
 
ontest(function () {
  console.log('i win because i was the last one')
})
 
emitter.test('test')

API

var once = nextEvent(emitter, name)

Create a new once function. Pass an event handler to once that should be called the next time name is emitted.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i next-event

Weekly Downloads

1,945

Version

1.0.0

License

MIT

Last publish

Collaborators

  • mafintosh