我有一系列的承诺(主要是ajax调用,但也有一些区别)。
我这样叫它们,我的问题是我还需要混合一些不返回承诺的标准函数,我已经在下面尝试过了,这是正确的方法吗?
基本上我想让promise A、B和C运行,然后执行我的非promise方法,一旦这些都完成了,就继续promise D和E。
this.promiseA()
.then(this.promiseB)
.then(this.promiseC)
.then(function(){
//do some methods that do not return promises
})
.then(this.promiseD)
.then(this.promiseE);发布于 2015-06-09 22:03:53
this.promiseA()
.then(this.promiseB)
.then(this.promiseC)
.then(function(){
//do some methods that do not return promises
// modify original promise here , else original promise
// passed to next `.then` in chain
// return $.when(true);
})
.then(this.promiseD)
.then(this.promiseE);发布于 2016-08-04 06:52:23
then函数可以返回任何内容,包括未定义的内容。如果需要,这一切都被封装在一个新的Promise中,以便链可以继续。
如果你的函数返回一个Promise或thenable,那么当这个对象被填满时,链会继续。然后,promiseD将接收此thenable的解析值。
如果您的函数返回立即值、null或未定义的值,则链将立即继续。promiseD将接收所述值。
所以,是的,您的解决方案是正确的。
https://stackoverflow.com/questions/30734192
复制相似问题