1 min readJun 7, 2019
If the outer observable — to which a flattening operator, like mergeMap
, is applied — completes, it means that no further inner observables will be created (as there will be no future next
notifications from which to create them). However, an incomplete inner observable will continue to emit notifications and those will be flattened.
For example, this will emit next
notifications forever:
interval(5000).pipe(
take(1),
mergeMap(() => interval(1000))
).subscribe(value => console.log(value));
If the inner observable in the example completed, the composed observable would complete when the inner observable completed.
For example, this will emit 10 next
notifications:
interval(5000).pipe(
take(1),
mergeMap(() => interval(1000).pipe(
take(10)
))
).subscribe(value => console.log(value));