Skip to content

Instantly share code, notes, and snippets.

@toddzebert
Last active March 8, 2017 05:45
Show Gist options
  • Save toddzebert/99dacd778c189201a8589bdd611790d8 to your computer and use it in GitHub Desktop.
Save toddzebert/99dacd778c189201a8589bdd611790d8 to your computer and use it in GitHub Desktop.
Flattened Async Callback example w/"all" & "race" patterns - check the console log
// requires https://gist.github.com/toddzebert/d41f06a7a33f5ada1557637a89278531
// requires https://gist.github.com/toddzebert/5958be630e81bb9ba16fb6931c339c88
var posts = [], data = { id: 4 };
var resolveAd = function(res) {
data.ad = res;
console.log(data);
}
var resolvePosts = function(res) {
data.posts = posts;
race([getAd(), getAd(), getAd()], resolveAd);
}
var resolveFeed = function (res) {
data.feed = res;
var getPosts = data.feed.map(post => getPost(post));
all(getPosts, resolvePosts);
}
var resolveProfile = function (res) {
data.profile = res;
getFeed(data, resolveFeed);
}
var resolveAuth = function (res) {
data.auth = res;
getProfile(data, resolveProfile);
}
getAuth(data, resolveAuth);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment