Last active
July 19, 2018 17:48
-
-
Save pulkitsinghal/16fa0444f86c7cfdd1e9ae67c8d614d0 to your computer and use it in GitHub Desktop.
How does promise.map() implementation behave in bluebird?
This file contains hidden or 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
var Promise = require('bluebird'); | |
var tests = [ | |
"hell", | |
"hell", | |
"hell", | |
"heaven", | |
"hell" | |
]; | |
var networkCall = function(test) { | |
if (test == "heaven") { | |
console.log('failure'); | |
return Promise.reject(); | |
} else { | |
console.log('great success'); | |
return Promise.resolve(); | |
} | |
}; | |
return Promise.map( | |
tests, | |
function(test) { | |
return networkCall(test) | |
.catch(function(){ | |
console.log('forgiveness is key if you wish to continue with the rest'); | |
return Promise.resolve(); | |
}) | |
} | |
) | |
.then(function(){ | |
console.log('then2', arguments); | |
return Promise.resolve(); | |
}) | |
.catch(function(){ | |
console.log('catch2', arguments); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment