https://kotlinlang.org logo
#coroutines
Title
# coroutines
l

louiscad

09/26/2018, 9:54 PM
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

elizarov

09/27/2018, 6:36 AM
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

louiscad

09/27/2018, 9:41 AM
I used
GlobalScope.launch(coroutineContext + context)
. Here's the gist for reference: https://gist.github.com/LouisCAD/ec559f6d62f796e9287145c4797400f7
4 Views