Hi all, is it a good idea to pass around instance...
# coroutines
s
Hi all, is it a good idea to pass around instances of
CoroutineScope
? Let's say I have a function that calls
launch
. I could do it like this:
Copy code
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
Copy code
fun doSomething(scope: CoroutineScope) {
  scope.launch {
    ...
  }
}
but it doesn't feel right. Or should I better use
Copy code
suspend fun doSomething() {
  coroutineScope {
    launch {
      ...
    }
  }
}
but then I create a new scope, right?
g
s
I currently struggle with mocking and verifying the variant
fun CoroutineScope.bar()
whereas
fun bar(scope: CoroutineScope)
seems to be simpler in this regard.
g
yeah...
suspend
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.