Last active
September 22, 2015 02:27
-
-
Save flockonus/225ed2f488932eeffdef to your computer and use it in GitHub Desktop.
Promise Fail Test
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 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)); |
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 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')) |
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 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