Last active
August 29, 2015 14:23
-
-
Save jdelStrother/31d2371e7f2c43260eef to your computer and use it in GitHub Desktop.
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 a = Promise.reject(new Error('load failed')).delay(100) | |
| var b = Promise.resolve(123).delay(50) | |
| var queue = [a,b] | |
| function processQueue() { | |
| var next = queue.shift() | |
| if (next) { | |
| return next.catch(processQueue) | |
| } else { | |
| return Promise.reject(new Error('no images left in queue')) | |
| } | |
| } | |
| processQueue().then(function(img){ | |
| console.log('Got image', img) | |
| }).catch(function(e){ | |
| console.log('No images successfully loaded') | |
| }) | |
| // catch any remaining failures silently | |
| Promise.settle(queue).catch() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment