You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
758 B
JavaScript
44 lines
758 B
JavaScript
"use strict";
|
|
|
|
var eventEmitter = new (require('events')).EventEmitter();
|
|
|
|
|
|
eventEmitter.all = function(events, callback) {
|
|
var eventList = events.slice(0);
|
|
|
|
function onEvent(event) {
|
|
eventEmitter.on(events[event], function() {
|
|
eventList.splice(eventList.indexOf(events[event]), 1);
|
|
|
|
if (eventList.length === 0) {
|
|
callback();
|
|
}
|
|
});
|
|
}
|
|
|
|
for (var ev in events) {
|
|
if (events.hasOwnProperty(ev)) {
|
|
onEvent(ev);
|
|
}
|
|
}
|
|
};
|
|
|
|
eventEmitter.any = function(events, callback) {
|
|
function onEvent(event) {
|
|
eventEmitter.on(events[event], function() {
|
|
if (events !== null) {
|
|
callback();
|
|
}
|
|
|
|
events = null;
|
|
});
|
|
}
|
|
|
|
for (var ev in events) {
|
|
if (events.hasOwnProperty(ev)) {
|
|
onEvent(ev);
|
|
}
|
|
}
|
|
};
|
|
|
|
module.exports = eventEmitter; |