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

Listening with a wildcard on once and emitting a certain event #31

Closed
molnarg opened this issue Sep 25, 2011 · 2 comments
Closed

Listening with a wildcard on once and emitting a certain event #31

molnarg opened this issue Sep 25, 2011 · 2 comments

Comments

@molnarg
Copy link

molnarg commented Sep 25, 2011

I would expect this listener to run only once, but it isn't removed after fired:

var type = 'test1.foo.bar';
var type2 = 'test1.foo.*';
var functionA = function() { test.ok(true, 'Event was fired'); };

emitter.once(type2, functionA);
emitter.emit(type);
emitter.emit(type);

test.expect(1);

This case is very similar to to unit test number 7 here: https://github.com/hij1nx/EventEmitter2/blob/master/test/wildcardEvents/ttl.js but the type and type2 are interchanged.

Is this behaviour intentional?

@molnarg
Copy link
Author

molnarg commented Sep 26, 2011

I'm sorry, this is not the right test case for this bug.

I realized that the bug that I'm facing can be seen only in a more special case, which is described by this short test function:

emitter = new EventEmitter2({wildcard: true});

function test() {
  emitter.once('event.*', function(id) { console.log("callback #1, event #" + id); });
  emitter.emit('event.x', 1);

  emitter.once('event.x', function(id) { console.log("callback #2, event #" + id); });
  emitter.emit('event.x', 2);

  emitter.once('event.*', function(id) { console.log("callback #3, event #" + id); });
  emitter.emit('event.y', 3);

  emitter.once('event.y', function(id) { console.log("callback #4, event #" + id); });
  emitter.emit('event.y', 4);
};

test();

If you run this code snippet, you get this output:

callback #1, event #1
callback #2, event #2
callback #3, event #3
callback #4, event #4
callback #3, event #4

The point is that callback #3 isn't removed after it's called, and this is not the intended behaviour as I understand.

@heapwolf
Copy link
Member

heapwolf commented Nov 6, 2012

Please add this to the test suite if it is still relevant.

@heapwolf heapwolf closed this as completed Nov 6, 2012
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