Trying to cancel flow emission when a certain scop...
# coroutines
Trying to cancel flow emission when a certain scope (not the collector scope) dies. I thought
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?
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?
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