我有一系列的承诺链,它们花了足够的时间来完成。下面是链设置示例:
myJob1()
.then(myJob2)
.then(myJob3)
.then(myJob4)
.then(myJob5)
.then(myJob6)
.catch(myJobError);同时,当此作业运行时,如果UI上的人员认为要取消它,那么在任何阶段/功能执行中如何取消它?
可能的解决方案是什么?
发布于 2017-08-21 20:05:47
没有办法取消promise (记住,每个thens都返回一个新的promise)或清除then回调。
你可能正在寻找像redux-observable这样的东西,在那里你可以指定子句,直到promise execution是实际的。
更多详情请看:https://github.com/redux-observable/redux-observable/blob/master/docs/recipes/Cancellation.md
作为替代方案,我可能只建议您创建和管理一些标志,用于确定是否需要进一步的处理:
// Inside each of promises in chain
if (notCancelled) {
callAjax(params).then(resolve);
}或者拒绝:
// Inside each of promises in chain
if (cancelled) {
// Will stop execution of promise chain
return reject(new Error('Cancelled by user'));
}https://stackoverflow.com/questions/45796488
复制相似问题