如何等待两个承诺的结果,然后做一些事情? [英] How to wait for result of two promises, then do something?
本文介绍了如何等待两个承诺的结果,然后做一些事情?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好吧,主题.想不通...
Well, subject. Can't figure out...
条件:两个 promise 都是异步启动的,并且不是一个接一个.像这样:
Condition: both promises start asynchronously and not one after another. Like this:
spashGoing.then(doSomethingForItself());
writingGoing.then(doSomethingForItself2());
DoSomethingAfterBothPromises()
P.S. 我使用 WinJS 的 promise,而不是 ES2015/ES2016,但它们没有大的差异.
P. S. I use promises from WinJS, not the ES2015/ES2016, but they don't have big defferences.
推荐答案
感谢@Evan Trimboli 和 .join
!请参阅主题下的评论.我去了 this 并找到了更漂亮的解决方案 此处:
Thanks @Evan Trimboli with .join
! See in comment under topic. I went to this and found more beatiful solution here:
WinJS.Promise.join({
p1: p1,
p2: p2,
m3: 3})
.then(function (args) {
//args.p1 = null
//args.p2 = promise with handle to file
//args.m3 = 3
console.log("Joined promise completed");
}, function (error) {
console.log("Joined promise error '" + error + "' occured but was handled");
}).done();
这篇关于如何等待两个承诺的结果,然后做一些事情?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文