No, takeWhile can leak subscriptions for the same reasons as takeUntil. However, the placement of a takeWhile will affect how it behaves, as it calls the specified callback only when a value is received. So there’s no general rule for where a takeWhile should be placed.

Also, as Stas Rivkin pointed out in his response, takeWhile is less suitable as an indirect unsubscription mechanism. It depends on a value being emitted for the this.isAlive flag to be checked, which means the any unsubscription will occur later than the component’s destruction — if at all.

In you code, you don’t have a subscription to another observable to leak — you’re just mapping the value — but you do have the problem that Stas highlighted.

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