https://kotlinlang.org logo
Title
p

Paul Woitaschek

07/01/2019, 8:58 PM
In the testing documentation: https://github.com/Kotlin/kotlinx.coroutines/tree/master/kotlinx-coroutines-test It's recommended to pass the scope through the constructor:
class Subject(val scope: CoroutineScope) {
    fun foo() {
        scope.launch {
            // launch uses the testScope injected in setup
        }
    }
}
But what do I actually pass in production code here?
s

streetsofboston

07/01/2019, 9:01 PM
It depends.... If you're an Android dev and this is part of your ViewModel, it would be a
MainScope()
or a
viewModelScope
. Or you create one on your own:
CoroutineScope(Job() + <http://Dispatchers.IO|Dispatchers.IO>)
for example