如何打破 Promises/A 的处理程序顺序?
例如
如果我们有序列:
method1().then(method2())
.then(method3(), errorHandler3());
在 method2() 中,我们决定打乱顺序,不再继续 method3() 或 errorHandler3()。我们应该怎么做?
最佳答案
您可以返回一个永远不会从 method2()
产生的函数中解析的 promise 。
但是,这没有多大意义,因为“破坏序列”实际上意味着进入错误状态,应该可以处理。
也许你更想
method1().then(function method2(res) {
// do something
if (/* you want to break*/)
throw new Error("reason for breaking");
else
return when(/* what is done */).then(method3(), errorHandler3());
});
关于javascript - 如何破坏 Promises/A 的序列处理程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16902339/