2014-05-13 12:09:21 -04:00
|
|
|
"use strict";
|
|
|
|
|
|
2014-08-26 11:35:45 -04:00
|
|
|
var eventEmitter = new (require('events')).EventEmitter();
|
2014-03-17 12:53:31 -04:00
|
|
|
|
2014-06-02 17:33:44 -04:00
|
|
|
|
|
|
|
|
eventEmitter.all = function(events, callback) {
|
2014-10-04 16:18:11 -04:00
|
|
|
var eventList = events.slice(0);
|
|
|
|
|
|
2015-04-27 20:26:02 -04:00
|
|
|
events.forEach(function onEvent(event) {
|
|
|
|
|
eventEmitter.on(event, function() {
|
|
|
|
|
var index = eventList.indexOf(event);
|
|
|
|
|
if (index === -1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
eventList.splice(index, 1);
|
2014-10-04 16:18:11 -04:00
|
|
|
if (eventList.length === 0) {
|
2014-08-01 17:02:07 -04:00
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-04-27 20:26:02 -04:00
|
|
|
});
|
2014-06-02 17:33:44 -04:00
|
|
|
};
|
|
|
|
|
|
2014-06-04 15:57:00 -04:00
|
|
|
eventEmitter.any = function(events, callback) {
|
2015-04-27 20:26:02 -04:00
|
|
|
events.forEach(function onEvent(event) {
|
|
|
|
|
eventEmitter.on(event, function() {
|
2014-08-01 17:02:07 -04:00
|
|
|
if (events !== null) {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
events = null;
|
|
|
|
|
});
|
2015-04-27 20:26:02 -04:00
|
|
|
});
|
2014-06-04 15:57:00 -04:00
|
|
|
};
|
|
|
|
|
|
2014-05-13 12:09:21 -04:00
|
|
|
module.exports = eventEmitter;
|