From 58912467000af7108bec3af1379a6e5a1a762ef1 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Mon, 2 Jun 2014 17:33:44 -0400 Subject: [PATCH] emitter.all --- src/emitter.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/emitter.js b/src/emitter.js index aa88cd5024..93e212c05b 100644 --- a/src/emitter.js +++ b/src/emitter.js @@ -3,4 +3,21 @@ var events = require('events'), eventEmitter = new events.EventEmitter(); + +eventEmitter.all = function(events, callback) { + for (var ev in events) { + if (events.hasOwnProperty(ev)) { + (function(ev) { + eventEmitter.on(events[ev], function() { + events.splice(events.indexOf(ev), 1); + + if (events.length === 0) { + callback(); + } + }); + }(ev)); + } + } +}; + module.exports = eventEmitter; \ No newline at end of file