-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
Description
When using .launchIn(this) inside a whileSubscribed block, the flow collection is not cancelled when subscribers drop to zero. This happens because launchIn() launches a coroutine in the
store's scope and returns immediately, so the whileSubscribed block completes without waiting for the flow.
The result is that the flow continues running indefinitely in the background, even when the screen is closed and there are no subscribers. This causes bugs like duplicate side effects,
stale state updates, and memory leaks.
The correct approach is to use .consume() which is a suspending function that properly respects cancellation.
Request
- Add a prominent warning in the documentation (red banner/callout) for the whileSubscribed plugin explicitly stating that .launchIn() should never be used inside the block, and .consume() should be used instead.
- Add a lint check to the FlowMVI IDE plugin that detects usage of .launchIn() inside whileSubscribed blocks and reports it as a warning or error, suggesting to use .consume() instead.
Reactions are currently unavailable