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

In this post, we will see how to resolve How to use switchMap to subscribe only to the last, while using a concurrent parameter (only available in mergeMap)?

Question:

I have this code:
https://stackblitz.com/edit/so-74114000-n5t8dl?devtoolsheight=100&file=index.ts%3AL30
It’s faking a couple web requests with a max of 3 concurrent using mergeMap.
Output:
I am missing one thing: I would like the “DONE” message to appear only at the end, once all the request are done. Currently the “DONE” message is appearing after each request.

Best Answer:

Instead of emitting each result as they are received, you can emit an array of all results once the source completes using toArray:
Output:
StackBlitz

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com