/es-promise-test.160519.js Secret
Created
May 19, 2016 09:56
基于ES6 Promise的中止过程功能尝试
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
let failingStep = function () { | |
console.log('向失败前进……'); | |
return new Promise((resolve, reject) => { | |
setTimeout(reject, 1000, '计划内的失败'); | |
}); | |
}; | |
let catchStep = function (reason) { | |
console.log(`遇到了错误:${reason}`); | |
return new Promise(() => {}); | |
}; | |
let followingStep = function () { | |
console.log('这个步骤不应当被执行'); | |
}; | |
failingStep().catch(catchStep).then(followingStep); | |
/* | |
* 运行结果 | |
* | |
* 向失败前进…… - 0s | |
* 遇到了错误:计划内的失败 - 1s | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment