Browse Source

amberc.js: add Combo 'library'

taken from http://howtonode.org/control-flow
Manfred Kroehnert 12 years ago
parent
commit
7bce0e2891
1 changed files with 24 additions and 0 deletions
  1. 24 0
      bin/amberc.js

+ 24 - 0
bin/amberc.js

@@ -21,6 +21,30 @@ function map(array, filter, callback) {
 	});
 }
 
+function Combo(callback) {
+  this.callback = callback;
+  this.items = 0;
+  this.results = [];
+}
+
+Combo.prototype = {
+  add: function () {
+    var self = this,
+        id = this.items;
+    this.items++;
+    return function () {
+      self.check(id, arguments);
+    };
+  },
+  check: function (id, arguments) {
+    this.results[id] = Array.prototype.slice.call(arguments);
+    this.items--;
+    if (this.items == 0) {
+      this.callback.apply(this, this.results);
+    }
+  }
+};
+
 console.time('Compile Time');
 
 var defaults = function() {