Skip to content

Instantly share code, notes, and snippets.

@jdelStrother
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save jdelStrother/31d2371e7f2c43260eef to your computer and use it in GitHub Desktop.

Select an option

Save jdelStrother/31d2371e7f2c43260eef to your computer and use it in GitHub Desktop.
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