svenjacobs
01/29/2019, 7:01 AMCoroutineScope
? Let's say I have a function that calls launch
. I could do it like this:
fun doSomething() {
GlobalScope.launch {
...
}
}
but what if I want the launch
block to be tied to the outer scope? So if the outer scope is terminated so should the launch
block. What I tried is
fun doSomething(scope: CoroutineScope) {
scope.launch {
...
}
}
but it doesn't feel right. Or should I better use
suspend fun doSomething() {
coroutineScope {
launch {
...
}
}
}
but then I create a new scope, right?ghedeon
01/29/2019, 8:42 AMsvenjacobs
01/29/2019, 8:47 AMfun CoroutineScope.bar()
whereas fun bar(scope: CoroutineScope)
seems to be simpler in this regard.ghedeon
01/29/2019, 10:00 AMsuspend
is nice and subtle, but this CoroutineScope
all over my API... idk, man, I have mixed feelings. Curious to check how it's done in Go now.