Created
May 30, 2018 22:52
-
-
Save rebolyte/36954a756e15a5f58a501d80fe0afd66 to your computer and use it in GitHub Desktop.
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
// Promise.resolve(ids).then(ids => { | |
// return ids.reduce((cur, next) => { | |
// return cur.then(() => { | |
// return doThingThatReturnsPromise(next); | |
// }); | |
// }, Promise.resolve()); | |
// }).then(() => { | |
// console.log('all done'); | |
// }).catch(err => { | |
// console.error(err); | |
// }); | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
data = [0, 1, 2]; | |
(async function() { | |
try { | |
let responses = await data.reduce((cur, next) => { | |
return cur.then(async function() { | |
console.log('start'); | |
return await sleep(1000); | |
}); | |
}, Promise.resolve()); | |
console.log('done'); | |
} catch (err) { | |
console.error(err); | |
} | |
}()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment