Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listener execution order regarding wildcards #306

Open
mathulbrich opened this issue Oct 11, 2023 · 1 comment
Open

Listener execution order regarding wildcards #306

mathulbrich opened this issue Oct 11, 2023 · 1 comment

Comments

@mathulbrich
Copy link

Recently we got some strange behavior with listeners that use wildcards. Apparently those listeners are executed after others that don't have wildcard, ignoring the register order (and even prependListener priority rule). See a example bellow:

const emitter = new EventEmitter2({
  delimiter: ".",
  wildcard: true,
});

emitter.on("test.*", () => console.log(`EMITTER CALLBACK 1`));
emitter.on("test.foo", () => console.log(`EMITTER CALLBACK 2`));
emitter.emit("test.foo");

// Output
// EMITTER CALLBACK 2
// EMITTER CALLBACK 1

Shouldn't the execution order be the first listener with wildcard, then the second after? It seems that the current behavior is prioritizing the event without wildcard. The problem is still the same after change to use prependListener.

emitter.prependListener("test.*", () => console.log(`EMITTER CALLBACK 1`));
emitter.on("test.foo", () => console.log(`EMITTER CALLBACK 2`));
emitter.emit("test.foo");

// Output
// EMITTER CALLBACK 2
// EMITTER CALLBACK 1

There was another issue about this (#94), but was closed by inactivity. I want to re-open this topic again.

@klutzer
Copy link

klutzer commented Oct 11, 2023

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants