Skip to content

Instantly share code, notes, and snippets.

@iptpv
Created February 12, 2016 05:24
Show Gist options
  • Save iptpv/8be2732a6a245787bf7c to your computer and use it in GitHub Desktop.
Save iptpv/8be2732a6a245787bf7c to your computer and use it in GitHub Desktop.
function asyncForeach(array, cb, stop) {
var index = 0;
function done() {
if (index > array.length - 1) {
return stop();
}
cb(array[index], index, done);
index++;
};
done();
}
asyncForeach(['1', '2', '3'], function(item, index, done) {
setTimeout(function() {
console.log(item);
done();
}, 1000);
}, function() {
console.log('end');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment