Skip to content

Instantly share code, notes, and snippets.

@tywong
Created September 22, 2016 01:41
Show Gist options
  • Save tywong/1435eedc96b9508d42fbbb4e7e37544f to your computer and use it in GitHub Desktop.
Save tywong/1435eedc96b9508d42fbbb4e7e37544f to your computer and use it in GitHub Desktop.
const Promise = require('bluebird');
let array = [
10, 10, 10, 10, 10, 10
];
return Promise.reduce(array,
(total, key, idx) => {
console.log(idx);
if(total == 20)
return Promise.reject(total);
else {
return Promise.resolve(total+key);
}
}, 0
)
.then( x => console.log("then", x))
.catch( x => console.log("catch", x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment