Trying to cancel flow emission when a certain scope (not the collector scope) dies. I thought
flowOn
would help but the scope there can't have a Job, which makes sense in the end. So I'm thinking of
Copy code
flow.onEach { myScope.ensureActive() }
Is this the only way to do it? Are there any concerns other than performance?
v
Valtteri Puonti
02/10/2021, 11:25 AM
What you're trying to accomplish seems quite counter intuitive when thinking in terms of structured concurrency.
Is there a reason why you cannot collect in the cancelling scope?
n
natario1
02/10/2021, 11:28 AM
The reason is that I'm not collecting the flow, just exposing it. But at the same time, I don't want to allow it to be collected after some certain event happens (myScope dies). Not sure if there are better ways to do so