@sovpro/ocafe
Version:
Once a callback attached to the first emitted event
43 lines (30 loc) • 1.08 kB
Markdown
Once a callback attached to the first emitted event
[](https://github.com/sovpro/ocafe/commits/master)
```js
var cancel = ocafe (
event_emitter
, 'thisEvent'
, thisEventCallback
, { event: 'thatEvent' ,
callback: thatEventCallback }
)
```
The first parameter must be an object that inherits EventEmitter or implements the EventEmitter interface.
Event names and callbacks may be passed as ordered arguments and/or objects having an `event` and `callback` property.
```js
var cancel = ocafe (
event_emitter
// , [name], [callback]
// , [name], [callback]
)
// cancelled is true if called before
// any of the events above emitted
var cancelled = cancel ()
```
`ocafe` returns a `cancel` function that, if called before one of the events is emitted, will prevent the callbacks passed as arguments from being run.