问题
At the moment I have all 3 requests running in parallel. Now I need to wait for the first one to finish before I fire the other 2 in parallel. This is what I have at the moment:
return Observable
.forkJoin(request1, request2, request3)
.map((successValues: boolean[]) => {
return successValues.every(x => x);
})
.do(success => {
if (success) {
this.store.dispatch({
type: actions.UPDATE_SUCCESS
});
}
});
回答1:
You should use the switchMap
operator.
request1.switchMap(response1 => {
Observable
.forkJoin(request2, request3)
.map((successValues: boolean[]) => {
return successValues.every(x => x);
})
.do(success => {
if (success) {
this.store.dispatch({
type: actions.UPDATE_SUCCESS
});
}
}
来源:https://stackoverflow.com/questions/40164578/how-to-wait-for-first-observable-to-finish-before-executing-others-in-parallel-u