The closest I came to is a combination of concat
for the two streams and merge
to make them run parallel.
Probably there are nicer way of doing this, but maybe it could be a starting point for you to fool around with:
import { delay, concatMap } from 'rxjs/operators';
import { of, concat, merge } from 'rxjs';
const reqA = of('a').pipe(delay(1000));
const reqB = of('b').pipe(delay(1000));
const reqC = of('c').pipe(delay(1000));
const reqX = of('x').pipe(delay(1000));
const reqY = of('y').pipe(delay(1000));
const reqZ = of('z').pipe(delay(1000));
const abc = [reqA, reqB, reqC];
const xyz = [reqX, reqY, reqZ];
merge(concat(...abc), concat(...xyz)).subscribe(
console.log
);
Here the StackBlitz i made with the code above.
So using concat on an observable array (your stream) makes sure there is only one observable running and on complete it will subscribe to the next observable in the array. With merge you can merge two streams abc
and xyz
meaning there will be two streams active at the same time.
UPDATE
I didn't know about the concurrent
parameter for the merge operator, so @lagoman his answer is the way to go. It was not clear for me from the documentation that it was possible. Not sure why they don't mention it explicitly, seems like a very useful feature.