RXJS - 3 parallel observables, then emit value and use this to call 3 observables in series
CLOSED
Maybe my question is a bit complicated but I can't figure out how to realize what I want.
Context
Three parallels observables emits value, then, when I've all three values, I modify them a little and then I want to call three observable in series.
Like the image below:
Now?
For the moment I managed to do this by putting my three parallel observable in a zip operator then subscribe to it, modify the value, and on complete, call the other one, subscribe, and on complete.. Three times !
this.service.Function(id) //return zip(Ob1, Ob2, Ob3)
.subscribe(
([val1, val2, val3]) => {
/*DO SOMETHING*/
this.tmp1 = val1;
this.tmp2 = val2;
this.tmp3 = val3;
},
() => {}, //on error
() => { //on complete
let newV1, newV2, newV3 = ;
[newV1, newV2, newV3 ] = [
this.tmp1.map(x => x.id2),
this.tmp2.map(x => x.id2),
this.tmp3.map(x => x.id2)
];
this.service.Function2(newV1)
.subscribe(res => {
//DO SOMETHING
},
() => {},
() => { //on complete
this.service.Function2(newV2)
.subscribe(res => {
//DO SOMETHING
},
() => {},
() => { //on complete
this.service.Function2(newV3)
.subscribe(res => {
//DO SOMETHING
},
() => {},
() => {
//DO SOMETHING
});
});
});
}
);
What I tried
I tried something different with switchMap and concat but concat doesn't return me my values as Array...
this.kycService.getDocuments(idNotif).pipe(
switchMap(([val1, val2, val3]) => {
this.tmp1 = val1;
this.tmp2 = val2;
this.tmp3 = val3;
let newV1, newV2, newV3 = ;
[newV1, newV2, newV3 ] = [
this.tmp1.map(x => x.id2),
this.tmp2.map(x => x.id2),
this.tmp3.map(x => x.id2)
];
return concat(this.service.Function2(newV1),this.service.Function2(newV2), this.service.Function2(newV3))
}))
.subscribe(([Ob_newV1, Ob_newV2, Ob_newV3]) => {
//DO SOMETHING
//[Ob_newV1, Ob_newV2, Ob_newV3] Doesn't work, I need to do val => {}
})
);
If you have any advice on what to use, I'm a bit confused by all the operators/functions in RXJS..
Thank you in advance
My solution
this.kycService.getDocuments(idNotif).pipe(
switchMap(([val1, val2, val3]) => {
this.tmp1 = val1;
this.tmp2 = val2;
this.tmp3 = val3;
let newV1, newV2, newV3 = ;
[newV1, newV2, newV3 ] = [
this.tmp1.map(x => x.id2),
this.tmp2.map(x => x.id2),
this.tmp3.map(x => x.id2)
];
return concat(this.service.Function2(newV1),this.service.Function2(newV2), this.service.Function2(newV3))
}))
.subscribe((val) => {
//DO SOMETHING
//val is emitted every time my function2 complete, so I manage to deal with this and rearrange my data
})
);
angular rxjs
add a comment |
CLOSED
Maybe my question is a bit complicated but I can't figure out how to realize what I want.
Context
Three parallels observables emits value, then, when I've all three values, I modify them a little and then I want to call three observable in series.
Like the image below:
Now?
For the moment I managed to do this by putting my three parallel observable in a zip operator then subscribe to it, modify the value, and on complete, call the other one, subscribe, and on complete.. Three times !
this.service.Function(id) //return zip(Ob1, Ob2, Ob3)
.subscribe(
([val1, val2, val3]) => {
/*DO SOMETHING*/
this.tmp1 = val1;
this.tmp2 = val2;
this.tmp3 = val3;
},
() => {}, //on error
() => { //on complete
let newV1, newV2, newV3 = ;
[newV1, newV2, newV3 ] = [
this.tmp1.map(x => x.id2),
this.tmp2.map(x => x.id2),
this.tmp3.map(x => x.id2)
];
this.service.Function2(newV1)
.subscribe(res => {
//DO SOMETHING
},
() => {},
() => { //on complete
this.service.Function2(newV2)
.subscribe(res => {
//DO SOMETHING
},
() => {},
() => { //on complete
this.service.Function2(newV3)
.subscribe(res => {
//DO SOMETHING
},
() => {},
() => {
//DO SOMETHING
});
});
});
}
);
What I tried
I tried something different with switchMap and concat but concat doesn't return me my values as Array...
this.kycService.getDocuments(idNotif).pipe(
switchMap(([val1, val2, val3]) => {
this.tmp1 = val1;
this.tmp2 = val2;
this.tmp3 = val3;
let newV1, newV2, newV3 = ;
[newV1, newV2, newV3 ] = [
this.tmp1.map(x => x.id2),
this.tmp2.map(x => x.id2),
this.tmp3.map(x => x.id2)
];
return concat(this.service.Function2(newV1),this.service.Function2(newV2), this.service.Function2(newV3))
}))
.subscribe(([Ob_newV1, Ob_newV2, Ob_newV3]) => {
//DO SOMETHING
//[Ob_newV1, Ob_newV2, Ob_newV3] Doesn't work, I need to do val => {}
})
);
If you have any advice on what to use, I'm a bit confused by all the operators/functions in RXJS..
Thank you in advance
My solution
this.kycService.getDocuments(idNotif).pipe(
switchMap(([val1, val2, val3]) => {
this.tmp1 = val1;
this.tmp2 = val2;
this.tmp3 = val3;
let newV1, newV2, newV3 = ;
[newV1, newV2, newV3 ] = [
this.tmp1.map(x => x.id2),
this.tmp2.map(x => x.id2),
this.tmp3.map(x => x.id2)
];
return concat(this.service.Function2(newV1),this.service.Function2(newV2), this.service.Function2(newV3))
}))
.subscribe((val) => {
//DO SOMETHING
//val is emitted every time my function2 complete, so I manage to deal with this and rearrange my data
})
);
angular rxjs
.pipe(toArray())
?
– JB Nizet
Dec 28 '18 at 11:05
It seems like you're looking forforkJoin
but I'm not really sure what thesethis.service.Function2(...)
functions do
– martin
Dec 28 '18 at 11:21
@JBNizet it works but.. When I do this with.subscribe((val) => {
it emit the value only when all 3 (or 4 in the image) observable complete.. Without this, it emit the value every time my observable emit something.. I'll go without toArray and work on the response ! Thanks !
– Ben Thie
Dec 28 '18 at 11:27
add a comment |
CLOSED
Maybe my question is a bit complicated but I can't figure out how to realize what I want.
Context
Three parallels observables emits value, then, when I've all three values, I modify them a little and then I want to call three observable in series.
Like the image below:
Now?
For the moment I managed to do this by putting my three parallel observable in a zip operator then subscribe to it, modify the value, and on complete, call the other one, subscribe, and on complete.. Three times !
this.service.Function(id) //return zip(Ob1, Ob2, Ob3)
.subscribe(
([val1, val2, val3]) => {
/*DO SOMETHING*/
this.tmp1 = val1;
this.tmp2 = val2;
this.tmp3 = val3;
},
() => {}, //on error
() => { //on complete
let newV1, newV2, newV3 = ;
[newV1, newV2, newV3 ] = [
this.tmp1.map(x => x.id2),
this.tmp2.map(x => x.id2),
this.tmp3.map(x => x.id2)
];
this.service.Function2(newV1)
.subscribe(res => {
//DO SOMETHING
},
() => {},
() => { //on complete
this.service.Function2(newV2)
.subscribe(res => {
//DO SOMETHING
},
() => {},
() => { //on complete
this.service.Function2(newV3)
.subscribe(res => {
//DO SOMETHING
},
() => {},
() => {
//DO SOMETHING
});
});
});
}
);
What I tried
I tried something different with switchMap and concat but concat doesn't return me my values as Array...
this.kycService.getDocuments(idNotif).pipe(
switchMap(([val1, val2, val3]) => {
this.tmp1 = val1;
this.tmp2 = val2;
this.tmp3 = val3;
let newV1, newV2, newV3 = ;
[newV1, newV2, newV3 ] = [
this.tmp1.map(x => x.id2),
this.tmp2.map(x => x.id2),
this.tmp3.map(x => x.id2)
];
return concat(this.service.Function2(newV1),this.service.Function2(newV2), this.service.Function2(newV3))
}))
.subscribe(([Ob_newV1, Ob_newV2, Ob_newV3]) => {
//DO SOMETHING
//[Ob_newV1, Ob_newV2, Ob_newV3] Doesn't work, I need to do val => {}
})
);
If you have any advice on what to use, I'm a bit confused by all the operators/functions in RXJS..
Thank you in advance
My solution
this.kycService.getDocuments(idNotif).pipe(
switchMap(([val1, val2, val3]) => {
this.tmp1 = val1;
this.tmp2 = val2;
this.tmp3 = val3;
let newV1, newV2, newV3 = ;
[newV1, newV2, newV3 ] = [
this.tmp1.map(x => x.id2),
this.tmp2.map(x => x.id2),
this.tmp3.map(x => x.id2)
];
return concat(this.service.Function2(newV1),this.service.Function2(newV2), this.service.Function2(newV3))
}))
.subscribe((val) => {
//DO SOMETHING
//val is emitted every time my function2 complete, so I manage to deal with this and rearrange my data
})
);
angular rxjs
CLOSED
Maybe my question is a bit complicated but I can't figure out how to realize what I want.
Context
Three parallels observables emits value, then, when I've all three values, I modify them a little and then I want to call three observable in series.
Like the image below:
Now?
For the moment I managed to do this by putting my three parallel observable in a zip operator then subscribe to it, modify the value, and on complete, call the other one, subscribe, and on complete.. Three times !
this.service.Function(id) //return zip(Ob1, Ob2, Ob3)
.subscribe(
([val1, val2, val3]) => {
/*DO SOMETHING*/
this.tmp1 = val1;
this.tmp2 = val2;
this.tmp3 = val3;
},
() => {}, //on error
() => { //on complete
let newV1, newV2, newV3 = ;
[newV1, newV2, newV3 ] = [
this.tmp1.map(x => x.id2),
this.tmp2.map(x => x.id2),
this.tmp3.map(x => x.id2)
];
this.service.Function2(newV1)
.subscribe(res => {
//DO SOMETHING
},
() => {},
() => { //on complete
this.service.Function2(newV2)
.subscribe(res => {
//DO SOMETHING
},
() => {},
() => { //on complete
this.service.Function2(newV3)
.subscribe(res => {
//DO SOMETHING
},
() => {},
() => {
//DO SOMETHING
});
});
});
}
);
What I tried
I tried something different with switchMap and concat but concat doesn't return me my values as Array...
this.kycService.getDocuments(idNotif).pipe(
switchMap(([val1, val2, val3]) => {
this.tmp1 = val1;
this.tmp2 = val2;
this.tmp3 = val3;
let newV1, newV2, newV3 = ;
[newV1, newV2, newV3 ] = [
this.tmp1.map(x => x.id2),
this.tmp2.map(x => x.id2),
this.tmp3.map(x => x.id2)
];
return concat(this.service.Function2(newV1),this.service.Function2(newV2), this.service.Function2(newV3))
}))
.subscribe(([Ob_newV1, Ob_newV2, Ob_newV3]) => {
//DO SOMETHING
//[Ob_newV1, Ob_newV2, Ob_newV3] Doesn't work, I need to do val => {}
})
);
If you have any advice on what to use, I'm a bit confused by all the operators/functions in RXJS..
Thank you in advance
My solution
this.kycService.getDocuments(idNotif).pipe(
switchMap(([val1, val2, val3]) => {
this.tmp1 = val1;
this.tmp2 = val2;
this.tmp3 = val3;
let newV1, newV2, newV3 = ;
[newV1, newV2, newV3 ] = [
this.tmp1.map(x => x.id2),
this.tmp2.map(x => x.id2),
this.tmp3.map(x => x.id2)
];
return concat(this.service.Function2(newV1),this.service.Function2(newV2), this.service.Function2(newV3))
}))
.subscribe((val) => {
//DO SOMETHING
//val is emitted every time my function2 complete, so I manage to deal with this and rearrange my data
})
);
angular rxjs
angular rxjs
edited Dec 28 '18 at 11:35
Ben Thie
asked Dec 28 '18 at 11:00
Ben ThieBen Thie
1165
1165
.pipe(toArray())
?
– JB Nizet
Dec 28 '18 at 11:05
It seems like you're looking forforkJoin
but I'm not really sure what thesethis.service.Function2(...)
functions do
– martin
Dec 28 '18 at 11:21
@JBNizet it works but.. When I do this with.subscribe((val) => {
it emit the value only when all 3 (or 4 in the image) observable complete.. Without this, it emit the value every time my observable emit something.. I'll go without toArray and work on the response ! Thanks !
– Ben Thie
Dec 28 '18 at 11:27
add a comment |
.pipe(toArray())
?
– JB Nizet
Dec 28 '18 at 11:05
It seems like you're looking forforkJoin
but I'm not really sure what thesethis.service.Function2(...)
functions do
– martin
Dec 28 '18 at 11:21
@JBNizet it works but.. When I do this with.subscribe((val) => {
it emit the value only when all 3 (or 4 in the image) observable complete.. Without this, it emit the value every time my observable emit something.. I'll go without toArray and work on the response ! Thanks !
– Ben Thie
Dec 28 '18 at 11:27
.pipe(toArray())
?– JB Nizet
Dec 28 '18 at 11:05
.pipe(toArray())
?– JB Nizet
Dec 28 '18 at 11:05
It seems like you're looking for
forkJoin
but I'm not really sure what these this.service.Function2(...)
functions do– martin
Dec 28 '18 at 11:21
It seems like you're looking for
forkJoin
but I'm not really sure what these this.service.Function2(...)
functions do– martin
Dec 28 '18 at 11:21
@JBNizet it works but.. When I do this with
.subscribe((val) => {
it emit the value only when all 3 (or 4 in the image) observable complete.. Without this, it emit the value every time my observable emit something.. I'll go without toArray and work on the response ! Thanks !– Ben Thie
Dec 28 '18 at 11:27
@JBNizet it works but.. When I do this with
.subscribe((val) => {
it emit the value only when all 3 (or 4 in the image) observable complete.. Without this, it emit the value every time my observable emit something.. I'll go without toArray and work on the response ! Thanks !– Ben Thie
Dec 28 '18 at 11:27
add a comment |
1 Answer
1
active
oldest
votes
Depends on your Observable types.
For hot observables (subjects, stores, etc), you will use combineLatest
.
For cold observables (of, HTTP calls, from promises, etc.), you will use forkJoin
.
Let's assume they're cold.
forkJoin(
first$.pipe(
map(result => /* transformation of your first observable */),
switchMap(result => this.myService.getNextObservableFromFirst())
),
second$.pipe(
map(result => /* transformation of your second observable */),
switchMap(result => this.myService.getNextObservableFromSecond())
),
third$.pipe(
map(result => /* transformation of your third observable */),
switchMap(result => this.myService.getNextObservableFromThird())
),
).subscribe([r1, r2, r3] => /* What to do once all calls are completed */);
It seems that adapted to your case, it would give
forkJoin(
first$.pipe(
map(result => result.id2),
switchMap(result => this.myService.Function2(result))
),
second$.pipe(
map(result => result.id2),
switchMap(result => this.myService.Function2(result))
),
third$.pipe(
map(result => result.id2),
switchMap(result => this.myService.Function2(result))
),
).subscribe([r1, r2, r3] => /* DO SOMETHING */);
OP says that asynchronous calls are made serially once the zip returns array of observables. ButforkJoin
does not handle this situation i guess.forkJoin
is suitable when parallel requests are made.
– Amit Chigadani
Dec 28 '18 at 11:10
All of his calls are already made, forkjoin is just there to make a callback once all the requests have been completed.
– trichetriche
Dec 28 '18 at 11:15
And by the way @AmitChigadani, I'm getting rid of thezip
here too
– trichetriche
Dec 28 '18 at 11:16
Ok, but still the patternfirst sequence as parallel and the second sequence as serial
is lost here. This would not behave in the same way as shown in the image.
– Amit Chigadani
Dec 28 '18 at 11:20
I don't see images (corporate proxy), So I rely on the provided code. And given the code he has provided, the statement you've just quoted is wrong : it's not 3 calls in parallel then 3 calls in serial, it's one call, then another call from the transformed result, times 3. But OP will try and tell me if it's not what he expected, in this case I will update my answer.
– trichetriche
Dec 28 '18 at 11:26
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53957455%2frxjs-3-parallel-observables-then-emit-value-and-use-this-to-call-3-observable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Depends on your Observable types.
For hot observables (subjects, stores, etc), you will use combineLatest
.
For cold observables (of, HTTP calls, from promises, etc.), you will use forkJoin
.
Let's assume they're cold.
forkJoin(
first$.pipe(
map(result => /* transformation of your first observable */),
switchMap(result => this.myService.getNextObservableFromFirst())
),
second$.pipe(
map(result => /* transformation of your second observable */),
switchMap(result => this.myService.getNextObservableFromSecond())
),
third$.pipe(
map(result => /* transformation of your third observable */),
switchMap(result => this.myService.getNextObservableFromThird())
),
).subscribe([r1, r2, r3] => /* What to do once all calls are completed */);
It seems that adapted to your case, it would give
forkJoin(
first$.pipe(
map(result => result.id2),
switchMap(result => this.myService.Function2(result))
),
second$.pipe(
map(result => result.id2),
switchMap(result => this.myService.Function2(result))
),
third$.pipe(
map(result => result.id2),
switchMap(result => this.myService.Function2(result))
),
).subscribe([r1, r2, r3] => /* DO SOMETHING */);
OP says that asynchronous calls are made serially once the zip returns array of observables. ButforkJoin
does not handle this situation i guess.forkJoin
is suitable when parallel requests are made.
– Amit Chigadani
Dec 28 '18 at 11:10
All of his calls are already made, forkjoin is just there to make a callback once all the requests have been completed.
– trichetriche
Dec 28 '18 at 11:15
And by the way @AmitChigadani, I'm getting rid of thezip
here too
– trichetriche
Dec 28 '18 at 11:16
Ok, but still the patternfirst sequence as parallel and the second sequence as serial
is lost here. This would not behave in the same way as shown in the image.
– Amit Chigadani
Dec 28 '18 at 11:20
I don't see images (corporate proxy), So I rely on the provided code. And given the code he has provided, the statement you've just quoted is wrong : it's not 3 calls in parallel then 3 calls in serial, it's one call, then another call from the transformed result, times 3. But OP will try and tell me if it's not what he expected, in this case I will update my answer.
– trichetriche
Dec 28 '18 at 11:26
|
show 1 more comment
Depends on your Observable types.
For hot observables (subjects, stores, etc), you will use combineLatest
.
For cold observables (of, HTTP calls, from promises, etc.), you will use forkJoin
.
Let's assume they're cold.
forkJoin(
first$.pipe(
map(result => /* transformation of your first observable */),
switchMap(result => this.myService.getNextObservableFromFirst())
),
second$.pipe(
map(result => /* transformation of your second observable */),
switchMap(result => this.myService.getNextObservableFromSecond())
),
third$.pipe(
map(result => /* transformation of your third observable */),
switchMap(result => this.myService.getNextObservableFromThird())
),
).subscribe([r1, r2, r3] => /* What to do once all calls are completed */);
It seems that adapted to your case, it would give
forkJoin(
first$.pipe(
map(result => result.id2),
switchMap(result => this.myService.Function2(result))
),
second$.pipe(
map(result => result.id2),
switchMap(result => this.myService.Function2(result))
),
third$.pipe(
map(result => result.id2),
switchMap(result => this.myService.Function2(result))
),
).subscribe([r1, r2, r3] => /* DO SOMETHING */);
OP says that asynchronous calls are made serially once the zip returns array of observables. ButforkJoin
does not handle this situation i guess.forkJoin
is suitable when parallel requests are made.
– Amit Chigadani
Dec 28 '18 at 11:10
All of his calls are already made, forkjoin is just there to make a callback once all the requests have been completed.
– trichetriche
Dec 28 '18 at 11:15
And by the way @AmitChigadani, I'm getting rid of thezip
here too
– trichetriche
Dec 28 '18 at 11:16
Ok, but still the patternfirst sequence as parallel and the second sequence as serial
is lost here. This would not behave in the same way as shown in the image.
– Amit Chigadani
Dec 28 '18 at 11:20
I don't see images (corporate proxy), So I rely on the provided code. And given the code he has provided, the statement you've just quoted is wrong : it's not 3 calls in parallel then 3 calls in serial, it's one call, then another call from the transformed result, times 3. But OP will try and tell me if it's not what he expected, in this case I will update my answer.
– trichetriche
Dec 28 '18 at 11:26
|
show 1 more comment
Depends on your Observable types.
For hot observables (subjects, stores, etc), you will use combineLatest
.
For cold observables (of, HTTP calls, from promises, etc.), you will use forkJoin
.
Let's assume they're cold.
forkJoin(
first$.pipe(
map(result => /* transformation of your first observable */),
switchMap(result => this.myService.getNextObservableFromFirst())
),
second$.pipe(
map(result => /* transformation of your second observable */),
switchMap(result => this.myService.getNextObservableFromSecond())
),
third$.pipe(
map(result => /* transformation of your third observable */),
switchMap(result => this.myService.getNextObservableFromThird())
),
).subscribe([r1, r2, r3] => /* What to do once all calls are completed */);
It seems that adapted to your case, it would give
forkJoin(
first$.pipe(
map(result => result.id2),
switchMap(result => this.myService.Function2(result))
),
second$.pipe(
map(result => result.id2),
switchMap(result => this.myService.Function2(result))
),
third$.pipe(
map(result => result.id2),
switchMap(result => this.myService.Function2(result))
),
).subscribe([r1, r2, r3] => /* DO SOMETHING */);
Depends on your Observable types.
For hot observables (subjects, stores, etc), you will use combineLatest
.
For cold observables (of, HTTP calls, from promises, etc.), you will use forkJoin
.
Let's assume they're cold.
forkJoin(
first$.pipe(
map(result => /* transformation of your first observable */),
switchMap(result => this.myService.getNextObservableFromFirst())
),
second$.pipe(
map(result => /* transformation of your second observable */),
switchMap(result => this.myService.getNextObservableFromSecond())
),
third$.pipe(
map(result => /* transformation of your third observable */),
switchMap(result => this.myService.getNextObservableFromThird())
),
).subscribe([r1, r2, r3] => /* What to do once all calls are completed */);
It seems that adapted to your case, it would give
forkJoin(
first$.pipe(
map(result => result.id2),
switchMap(result => this.myService.Function2(result))
),
second$.pipe(
map(result => result.id2),
switchMap(result => this.myService.Function2(result))
),
third$.pipe(
map(result => result.id2),
switchMap(result => this.myService.Function2(result))
),
).subscribe([r1, r2, r3] => /* DO SOMETHING */);
edited Dec 28 '18 at 11:28
answered Dec 28 '18 at 11:07
trichetrichetrichetriche
25.8k42152
25.8k42152
OP says that asynchronous calls are made serially once the zip returns array of observables. ButforkJoin
does not handle this situation i guess.forkJoin
is suitable when parallel requests are made.
– Amit Chigadani
Dec 28 '18 at 11:10
All of his calls are already made, forkjoin is just there to make a callback once all the requests have been completed.
– trichetriche
Dec 28 '18 at 11:15
And by the way @AmitChigadani, I'm getting rid of thezip
here too
– trichetriche
Dec 28 '18 at 11:16
Ok, but still the patternfirst sequence as parallel and the second sequence as serial
is lost here. This would not behave in the same way as shown in the image.
– Amit Chigadani
Dec 28 '18 at 11:20
I don't see images (corporate proxy), So I rely on the provided code. And given the code he has provided, the statement you've just quoted is wrong : it's not 3 calls in parallel then 3 calls in serial, it's one call, then another call from the transformed result, times 3. But OP will try and tell me if it's not what he expected, in this case I will update my answer.
– trichetriche
Dec 28 '18 at 11:26
|
show 1 more comment
OP says that asynchronous calls are made serially once the zip returns array of observables. ButforkJoin
does not handle this situation i guess.forkJoin
is suitable when parallel requests are made.
– Amit Chigadani
Dec 28 '18 at 11:10
All of his calls are already made, forkjoin is just there to make a callback once all the requests have been completed.
– trichetriche
Dec 28 '18 at 11:15
And by the way @AmitChigadani, I'm getting rid of thezip
here too
– trichetriche
Dec 28 '18 at 11:16
Ok, but still the patternfirst sequence as parallel and the second sequence as serial
is lost here. This would not behave in the same way as shown in the image.
– Amit Chigadani
Dec 28 '18 at 11:20
I don't see images (corporate proxy), So I rely on the provided code. And given the code he has provided, the statement you've just quoted is wrong : it's not 3 calls in parallel then 3 calls in serial, it's one call, then another call from the transformed result, times 3. But OP will try and tell me if it's not what he expected, in this case I will update my answer.
– trichetriche
Dec 28 '18 at 11:26
OP says that asynchronous calls are made serially once the zip returns array of observables. But
forkJoin
does not handle this situation i guess. forkJoin
is suitable when parallel requests are made.– Amit Chigadani
Dec 28 '18 at 11:10
OP says that asynchronous calls are made serially once the zip returns array of observables. But
forkJoin
does not handle this situation i guess. forkJoin
is suitable when parallel requests are made.– Amit Chigadani
Dec 28 '18 at 11:10
All of his calls are already made, forkjoin is just there to make a callback once all the requests have been completed.
– trichetriche
Dec 28 '18 at 11:15
All of his calls are already made, forkjoin is just there to make a callback once all the requests have been completed.
– trichetriche
Dec 28 '18 at 11:15
And by the way @AmitChigadani, I'm getting rid of the
zip
here too– trichetriche
Dec 28 '18 at 11:16
And by the way @AmitChigadani, I'm getting rid of the
zip
here too– trichetriche
Dec 28 '18 at 11:16
Ok, but still the pattern
first sequence as parallel and the second sequence as serial
is lost here. This would not behave in the same way as shown in the image.– Amit Chigadani
Dec 28 '18 at 11:20
Ok, but still the pattern
first sequence as parallel and the second sequence as serial
is lost here. This would not behave in the same way as shown in the image.– Amit Chigadani
Dec 28 '18 at 11:20
I don't see images (corporate proxy), So I rely on the provided code. And given the code he has provided, the statement you've just quoted is wrong : it's not 3 calls in parallel then 3 calls in serial, it's one call, then another call from the transformed result, times 3. But OP will try and tell me if it's not what he expected, in this case I will update my answer.
– trichetriche
Dec 28 '18 at 11:26
I don't see images (corporate proxy), So I rely on the provided code. And given the code he has provided, the statement you've just quoted is wrong : it's not 3 calls in parallel then 3 calls in serial, it's one call, then another call from the transformed result, times 3. But OP will try and tell me if it's not what he expected, in this case I will update my answer.
– trichetriche
Dec 28 '18 at 11:26
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53957455%2frxjs-3-parallel-observables-then-emit-value-and-use-this-to-call-3-observable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
.pipe(toArray())
?– JB Nizet
Dec 28 '18 at 11:05
It seems like you're looking for
forkJoin
but I'm not really sure what thesethis.service.Function2(...)
functions do– martin
Dec 28 '18 at 11:21
@JBNizet it works but.. When I do this with
.subscribe((val) => {
it emit the value only when all 3 (or 4 in the image) observable complete.. Without this, it emit the value every time my observable emit something.. I'll go without toArray and work on the response ! Thanks !– Ben Thie
Dec 28 '18 at 11:27