mergeMap(project: function: Observable, resultSelector: function: any, concurrent: number): Observable
mergeMap
?switchMap
each inner subscription is completed when the source emits, allowing only one active inner subscription. In contrast, mergeMap
allows for multiple inner subscriptions to be active at a time. Because of this, one of the most common use-case for mergeMap
is requests that should not be canceled, think writes rather than reads. Note that if order must be maintained concatMap
is a better option.mergeMap
maintains multiple active inner subscriptions at once it's possible to create a memory leak through long-lived inner subscriptions. A basic example would be if you were mapping to an observable with an inner timer, or a stream of dom events. In these cases, if you still wish to utilize mergeMap
you may want to take advantage of another operator to manage the completion of the inner subscription, think take
or takeUntil
. You can also limit the number of active inner subscriptions at a time with the concurrent
parameter, seen in example 5.