Coroutine builder `coroutineScope {}` will return ...
# coroutines
l
Coroutine builder
coroutineScope {}
will return when the provided suspend block and child coroutines end. Instead, is there anything that returns immediately when the block returns, cancelling child coroutines? I thought there would be prebuilt builder. This would be extremely useful on situations like:
Copy code
coroutineScope { // this suspends until someFlow is finished; needs alternative one
  val collected = someFlow.shareIn(this, ...)
  work(collected)
}
Ideal one to me:
Copy code
(some cool name)Scope { // someFlow.shareIn is cancelled after work is finished and block returns
  val collected = someFlow.shareIn(this, ...)
  work(collected)
}
n
I think you can just call
coroutineContext.cancelChildren
when done. I’ve never needed such a function. Generally using
WhileSubscribed()
is enough to avoid forever running shared flows.