소스 검색

amberc.js: add Combo 'library'

taken from http://howtonode.org/control-flow
Manfred Kroehnert 12 년 전
부모
커밋
7bce0e2891
1개의 변경된 파일24개의 추가작업 그리고 0개의 파일을 삭제
  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() {