11 Pend.prototype.go = function(fn) {
12 if (this.pending < this.max) {
15 this.waiting.push(fn);
19 Pend.prototype.wait = function(cb) {
20 if (this.pending === 0) {
23 this.listeners.push(cb);
27 Pend.prototype.hold = function() {
28 return pendHold(this);
31 function pendHold(self) {
36 if (called) throw new Error("callback called twice");
38 self.error = self.error || err;
40 if (self.waiting.length > 0 && self.pending < self.max) {
41 pendGo(self, self.waiting.shift());
42 } else if (self.pending === 0) {
43 var listeners = self.listeners;
45 listeners.forEach(cbListener);
48 function cbListener(listener) {
53 function pendGo(self, fn) {