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));

RxJS core team member; front-end developer; mentor; speaker; open-source contributor

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store