【发布时间】:2019-04-04 02:58:43
【问题描述】:
我试图在fetchLoansPromise 之前获取studentDataPromise,因为它取决于studentDataPromise 返回的数据。
这是我当前的代码:
Promise.all([studentDataPromise, fetchclassesPromise, fetchLoansPromise])
.then(() => {
toggleIsReady();
})
.catch(error => {
throw new Error(error);
});
这是当前的事件顺序:
-
toggleIsReady最初设置为 false,但现在为 true。 -
fetchLoansPromise- 无法获取它没有获取studentDataPromise -
studentDataPromise- 正确获取它 -
toggleIsReady- 现在设置为 false -
fetchclassesPromise- 正确获取它
有什么建议吗?
【问题讨论】:
-
如果
fetchLoansPromise需要studentDataPromise已解决,为什么要使用Promise.all来并行运行它们? -
如果你想要一个在另一个之前,不要使用
Promise.all。