Last active
March 7, 2017 09:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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