Skip to content

Instantly share code, notes, and snippets.

@znechai
Created September 1, 2019 13:02
Show Gist options
  • Save znechai/88f95435ad000964cb586943a1238b5b to your computer and use it in GitHub Desktop.
Save znechai/88f95435ad000964cb586943a1238b5b to your computer and use it in GitHub Desktop.
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