How to stop execution/cancel an event
elmatou opened this issue · comments
Marco commented
EventEmitter allow to chain listeners for an event. I would like to stop the listeners to be called at some point, pretty much like the return false
or e.preventDefault()
work on the DOM element event.
something like that :
eventEmitter = new EventEmitter()
eventEmitter
.on('connection', (e) => {
...
if (...) {
// here, cancel the event with some method.
}
})
.on('connection', (e) => {
...
// not called because stopped in the previous listener.
});
Are they any methods to do it ?
I know I can throw an error, but I'm not able to catch it some anywhere.
Luigi Pinca commented
Are they any methods to do it ?
No, it is not possible with eventemitter3
or the Node.js core EventEmitter
.
Marco commented
Thx for your response, I'm gonna go for the not very graceful throw 'stopping propagation'