Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[js] 第490天 如何取消promise? #2792

Open
haizhilin2013 opened this issue Aug 17, 2020 · 2 comments
Open

[js] 第490天 如何取消promise? #2792

haizhilin2013 opened this issue Aug 17, 2020 · 2 comments
Labels
js JavaScript

Comments

@haizhilin2013
Copy link
Collaborator

第490天 如何取消promise?

3+1官网

我也要出题

@haizhilin2013 haizhilin2013 added the js JavaScript label Aug 17, 2020
@Alex-Li2018
Copy link

promise的状态一经确定就不能被取消了

@chipooi
Copy link

chipooi commented Aug 20, 2020

Promise/A+标准规定了:原Promise对象跟新返回的对象状态一致。所以可以通过返回一个始终是pending状态的Promise对象来取消Promise。
Promise.resolve().then(() => {
console.log(1)
return new Promise(()=>{}) // 返回“pending”状态的Promise对象
}).then(() => {
// 后续的函数不会被调用
console.log(2)
}).catch(err => {
console.log(err)
}) // 只输出1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
js JavaScript
Projects
None yet
Development

No branches or pull requests

3 participants