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

Vikas Singh

06/14/2021, 10:56 AM
What's difference between CoroutineScope(Dispatchers.IO) + Job() and CoroutineScope(Dispatchers.IO+ Job())
m

mbonnin

06/14/2021, 11:00 AM
It's the same thing:
Copy code
/**
 * Adds the specified coroutine context to this scope, overriding existing elements in the current
 * scope's context with the corresponding keys.
 *
 * This is a shorthand for `CoroutineScope(thisScope + context)`.
 */
public operator fun CoroutineScope.plus(context: CoroutineContext): CoroutineScope =
    ContextScope(coroutineContext + context)
I wish I could "open in github" from IntelliJ depenencies but if you look for
CoroutineScope.kt
in the coroutines repo, you'll find it
CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>)
will add a Job by default so you can leave out the Job in all cases
d

Dominaezzz

06/14/2021, 11:58 AM
The latter elides an object allocation, so prefer that one if it makes sense in your code.
👍 1
v

Vikas Singh

06/14/2021, 1:00 PM
@mbonnin I can see in this method
👍 1
4 Views