Skip to content

Instantly share code, notes, and snippets.

View toddzebert's full-sized avatar
💭
coding, of course

Todd Zebert toddzebert

💭
coding, of course
View GitHub Profile
@toddzebert
toddzebert / getAd.js
Created March 27, 2017 04:06
getAd code for use with simAsync.js
// requires https://gist.github.com/toddzebert/996e297c1c081d19378eaf5f29dc75bb
var getAd = (function (dat) {
let i = 1;
// create a closure
const ad = function () {
return 'Ad#' + i++;
};
return function (dat) {
return simAsync(ad);
};
@toddzebert
toddzebert / getAds.js
Created March 27, 2017 04:08
getAds code for use with getAd.js, and simAsync.js
// requires https://gist.github.com/toddzebert/996e297c1c081d19378eaf5f29dc75bb
// requires https://gist.github.com/toddzebert/ec087188b813e6490abab2cf0feb2ad5
var getAds = function (data) {
return new Promise( (resolve, reject) => {
Promise.race([getAd(data), getAd(data), getAd(data)])
.then(result => {
data.ads = result; resolve(data);
})
.catch(result => {
data.ads = result; reject(data);
@toddzebert
toddzebert / promisesMain.js
Created March 27, 2017 04:13
"main" code that wraps all the individual promise steps together
// requires https://gist.github.com/toddzebert/135578e9faf006b73656c360b7e616e2
// requires https://gist.github.com/toddzebert/c9d75cd901897e7363bf142a90a2b2a1
// requires https://gist.github.com/toddzebert/bcd849a48676256eef8a795f8f03cfff
// requires https://gist.github.com/toddzebert/43c308b0e0f559b47ac487dcc8c06924
// requires https://gist.github.com/toddzebert/5d279f8a2104bef103273e5177ae3599
var data = { id: 4 };
getAuth(data)
.then(getProfile)
.then(getFeed)
.then(getPosts)