Skip to content

Instantly share code, notes, and snippets.

@SilentDepth
Created May 19, 2016 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SilentDepth/67866e565946e84b1409d16d294b6181 to your computer and use it in GitHub Desktop.
Save SilentDepth/67866e565946e84b1409d16d294b6181 to your computer and use it in GitHub Desktop.
基于ES6 Promise的中止过程功能尝试
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