Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // You probobly don't need a helper library for Promise/Async after all
- const seedValues = [Promise.resolve(777), Promise.resolve(888)];
- // reduce
- // Promise based
- seedValues
- .reduce((accumulator, currentValue) =>
- accumulator.then(v => currentValue.then(cv => v + cv))
- )
- .then(console.log.bind(console));
- // async
- seedValues
- .reduce(async (acc, c) => (await acc) + (await c))
- .then(console.log.bind(console));
- // simple map
- // Promise based
- Promise.all(seedValues.map(p => p.then(v => v.toString()))).then(
- console.log.bind(console)
- );
- // async
- Promise.all(seedValues.map(async p => (await p).toString())).then(
- console.log.bind(console)
- );
Advertisement
Add Comment
Please, Sign In to add comment