Now that `currentScope { }` is deprecated, should ...
# coroutines
l
Now that
currentScope { }
is deprecated, should I use its implementation,
CoroutineScope(coroutineContext)
instead? I have some code relying on it:
Copy code
suspend inline fun <E> ReceiveChannel<E>.doOnEach(
        context: CoroutineContext = EmptyCoroutineContext,
        noinline action: suspend (E) -> Unit
) = currentScope {
    launch(context) { consumeEach { action(it) } }
}
that would become:
Copy code
suspend inline fun <E> ReceiveChannel<E>.doOnEach(
        context: CoroutineContext = EmptyCoroutineContext,
        noinline action: suspend (E) -> Unit
) = CoroutineScope(coroutineContext).launch(context) { consumeEach { action(it) } }
e
That is one option. Alternative is to write
GlobalScope.launch(coroutineContex)
It looks more explicit to me and is slightly more efficient (one object less)..
We’ll be addressing channels and their integration with structured concurrency is a separate effort.
👍 5
l
I used
GlobalScope.launch(coroutineContext + context)
. Here's the gist for reference: https://gist.github.com/LouisCAD/ec559f6d62f796e9287145c4797400f7