Skip to content

Instantly share code, notes, and snippets.

@toddzebert
Last active March 7, 2017 09:33
Show Gist options
  • Save toddzebert/7c0aa1f1ee3be2d39d301bd875fead25 to your computer and use it in GitHub Desktop.
Save toddzebert/7c0aa1f1ee3be2d39d301bd875fead25 to your computer and use it in GitHub Desktop.
a simple implementation of a "all" callback pattern such that all the callback functions in the `entries` array complete successfully before progressing
var all = function (entries, cb) {
var finishers = entries.length;
var allCB = (function(cb) {
return function (res) {
if (res) {
if (--finishers === 0) cb(res);
} else {
cb(false);
}
}
})(cb);
entries.map(entry => { entry(data, allCB); });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment