Created
September 1, 2019 13:02
-
-
Save znechai/88f95435ad000964cb586943a1238b5b 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
function methodThatReturnsAPromise ( id ) { | |
return new Promise( ( resolve, reject ) => { | |
setTimeout( () => { | |
console.log( `Processing ${ id }` ); | |
resolve( id ); | |
}, 1000 ); | |
} ); | |
} | |
let result = [ 1, 2, 3 ].reduce( async ( accumulatorPromise, nextID ) => { | |
await accumulatorPromise; | |
return methodThatReturnsAPromise( nextID ); | |
}, Promise.resolve() ); | |
result.then( e => { | |
console.log( "Resolution is complete! Let's party." ) | |
} ); | |
// let result = [ 1, 2, 3 ].reduce( ( accumulatorPromise, nextID ) => { | |
// return accumulatorPromise.then( () => { | |
// return methodThatReturnsAPromise( nextID ); | |
// } ); | |
// }, Promise.resolve() ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment