Permalink
Browse files

Pass args alongside WaitForAny done event.

  • Loading branch information...
1 parent 1cf81d0 commit 71cc4cf5b68879567d3f9d113b6eec0819914abd @MathieuTurcotte committed May 7, 2013
Showing with 7 additions and 4 deletions.
  1. +1 −0 README.md
  2. +3 −1 lib/any.js
  3. +3 −3 tests/any.js
View
1 README.md
@@ -128,6 +128,7 @@ Start waiting on `EventEmitter` instances.
#### Event: 'done'
- index: the index of the `EventEmitter` that has fired
+- args...: the parameters returned by the `EventEmitter`
Emitted when the waiting criterion has been satisfied before timeout.
View
4 lib/any.js
@@ -14,8 +14,10 @@ function WaitForAny(options) {
util.inherits(WaitForAny, WaitForMultiple);
WaitForAny.prototype.handleDone = function(index) {
+ var args = Array.prototype.slice.call(arguments, 1);
+ args.unshift('done', index);
this.stopListening();
- this.emit('done', index);
+ this.emit.apply(this, args);
this.clear();
};
View
6 tests/any.js
@@ -39,7 +39,7 @@ exports["WaitForAny"] = {
test.done();
},
- "the index of the event emitter should be emitted": function(test) {
+ "the event emitter index and event parameters should be reemitted": function(test) {
var emittedIndex = -1;
var e1 = new events.EventEmitter();
@@ -53,8 +53,8 @@ exports["WaitForAny"] = {
waiter.add([e1, e2, e3]);
waiter.wait();
- e3.emit('done');
- test.equal(emittedIndex, 2);
+ e3.emit('done', 'arg1', 'arg2');
+ test.equal(emittedIndex, 2, 'arg1', 'arg2');
test.done();
},

0 comments on commit 71cc4cf

Please sign in to comment.