Reputation:
I'm looking for a way to add events such that they fire sequentially and optionally pass through. I'm wondering if there is anything like this natively in the Node API, or if not if anyone knows of a decent npm package that accomplishes this:
obj
.on('event-A', function(){
// log something()
// consume or stop the event
})
.on('event-A', function(){
// this never fires
});
Upvotes: 11
Views: 4014
Reputation: 18665
I don't know of any node-api allowing to cancel event dispatching. But you can take any node-compatible event library (node, pubsubjs, etc) and modify the dispatching function with these guidelines:
But note that:
Upvotes: 1
Reputation:
I just wrote a library (event-chains) that replicates the EventEmitter
API and provides cancelation via either rejected promises or by calling this.stop()
. Also steals an idea from signals
where you can have "single event" emitters.
Upvotes: 1