Make concurrent requests using rxjs mergeMap() is sequential

doe

I have 2 observables that should run concurrently, the code I have now seems to be running the 2 streams sequentially. StreamA$ completes then StreamB$ begins not as expected. How can I get the streams to run concurrently with mergeMap?

ngOnInit() {
  this.streamA$ = this.streamService.getStream(1);
  this.streamB$ = this.streamService.getOtherStream(2);
}

click() {
  console.log('clicked');
  this.streamA$
    .pipe(
      mergeMap(streamData => {
        console.log(this.streamB$);
        console.log(streamData);
        return this.streamB$;
      })         )
      .subscribe(data => {
        console.log(data);
      });
}
Will Alexander

mergeMap subscribes to the inner Observable every time the outer Observable emits a value. It is true that if the outer Observable emits multiple values, the inner one will be subscribed to concurrently, but it will always go outer->inner. If you're trying to combine the two Observables, try the following instead:

merge(this.streamA$, this.streamB$).subscribe();

This will create one single Observable which combines the emissions of the two others. Does that sound like what you're looking for?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Concurrent Ajax requests with Rxjs

How to make a lot of concurrent web requests using async and await?

mergeMap service in rxjs 6

RXJS: Conditional map or mergeMap

Angular RxJS mergeMap types

mergeMap() RXJS 3 observables

How to make concurrent HTTP requests with basic authentication

Getting Error when using mergeMap to merge two sequential subscriptions in Angular

How to make a sequence of http requests in Angular 6 using RxJS

Using React useEffect hook with rxjs mergeMap operator

Why is there a threshold of concurrent HTTP requests I can make using `HttpClient`?

RxJS: mergeMap operator cancelling other active requests when one of them throws an error

RxJS result with switchMap and mergeMap

Rxjs mergeMap: Concat 2 related Api Requests

Using MergeMap with the array of data received from another observable - RxJs Angular

how to optimize sequential processing of network requests between two servers in rxjs

undefined output while using mergeMap in Rxjs

How To Limit Concurrent API Requests In Angular Using RxJs

Hybrid of mergeMap and concatMap in rxjs

Rxjs make sequential calls using concatMap

What is the number of concurrent requests using SPDY in browser?

C# Running concurrent requests using WebTestRequest

RxJS: forkJoin mergeMap

RXJS MergeMap not getting executed

Rxjs how to use mergeMap?

Angular RxJS sequential requests issue

How to use switchMap to subscribe only to the last, while using a concurrent parameter (only available in mergeMap)?

Scala Requests module: Is it possible to make concurrent requests?

RxJS: Observable never completes when using mergeMap with concurrent