primus / eventemitter3

EventEmitter3 - Because there's also a number 2. And we're faster.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to stop execution/cancel an event

elmatou opened this issue · comments

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.

Are they any methods to do it ?

No, it is not possible with eventemitter3 or the Node.js core EventEmitter.

commented

Thx for your response, I'm gonna go for the not very graceful throw 'stopping propagation'