Skip to content

Commit

Permalink
parallelPerform serialPerform
Browse files Browse the repository at this point in the history
  • Loading branch information
richcollins committed Nov 6, 2013
1 parent 3fe6057 commit f107d33
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions lib/Array.js
Expand Up @@ -287,6 +287,57 @@
}
});
},

parallelPerform: function() {
var args = this.slice.call(arguments).slice();
var fn = args.pop();

if (this.length == 0) {
fn(null);
return;
}

var completed = 0;
var err = null;
var self = this;
args.push(function(error){
err = error;
completed ++;
if (completed == self.length) {
fn(err);
}
});
this.forEachCall.apply(this, args);
return this;
},

serialPerform: function(functionName) {
var args = this.slice.call(arguments).slice(1);
var fn = args.pop();

if (this.length == 0) {
fn(null);
return;
}

args.push(function(error){
if (error) {
fn(error);
return true;
} else {
return false;
}
});

for (var i = 0; i < this.length; i ++) {
if (this[i][functionName].apply(this.args)) {
break;
}
}

this.forEachCall.apply(this, args);
return this;
},

mapPerform: function(functionName)
{
Expand Down

0 comments on commit f107d33

Please sign in to comment.