Skip to content

Instantly share code, notes, and snippets.

@flockonus
Last active September 22, 2015 02:27
Show Gist options
  • Save flockonus/225ed2f488932eeffdef to your computer and use it in GitHub Desktop.
Save flockonus/225ed2f488932eeffdef to your computer and use it in GitHub Desktop.
Promise Fail Test
var failPromise = new Promise(function(accept,reject){
setTimeout(reject,1000,'fail');
});
// won't see the numbers logged, will skip to the fail
failPromise.then(()=> console.log(1)) .then(()=> console.log(2)) .catch((e)=> console.log(':::%s',e));
var failPromise = new Promise(function(accept,reject){
setTimeout(reject,1000,'fail');
});
// fail but then catch, and then recover
failPromise.then(()=> console.log(1)) .then(()=> console.log(2))
.catch((e)=> console.log(':::%s',e))
// there is a catch* this then() will execute either way!
.then(() => console.log('recovered'))
var failPromise = new Promise(function(accept,reject){
setTimeout(reject,10,'fail');
});
failPromise.then(
function win1(){
return 'win1'
}, function fail1(){
return 'fail1';
}).then(function win2(data){
console.log('win2',data);
}, function fail2(data){
console.log('fail2',data);
})
// => win2 fail1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment