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.
nodebb/src/emitter.js

36 lines
664 B
JavaScript

'use strict';
var eventEmitter = new (require('events')).EventEmitter();
eventEmitter.all = function (events, callback) {
var eventList = events.slice(0);
events.forEach(function onEvent(event) {
eventEmitter.on(event, function () {
var index = eventList.indexOf(event);
if (index === -1) {
return;
}
eventList.splice(index, 1);
if (eventList.length === 0) {
callback();
}
});
});
};
eventEmitter.any = function (events, callback) {
events.forEach(function onEvent(event) {
eventEmitter.on(event, function () {
if (events !== null) {
callback();
}
events = null;
});
});
};
module.exports = eventEmitter;