Reputation: 193
As codes shown below,
launchWithXXX
functions run in MainScope
? Are they creating the same coroutine environment for running both jobs?dispose()
is called?class A : CoroutineScope by MainScope() {
fun launchWithGlobalScope() {
GlobalScope.launch(coroutineContext) {
// Run jobs
}
}
fun launchWithClassScope() {
launch {
// Run jobs too
}
}
fun dispose() {
cancel()
}
}
Upvotes: 0
Views: 1391
Reputation: 6258
Answer for 1: No. MainScope
defines a scope for doing something with UI components. So it runs in the UI thread of your platform. GlobalScope
is a scope with an own thread pool and runs the coroutine with one of those threads.
Answer for 2: cancel
does only stop the MainScope
in your example and all coroutines created with this scope.
Upvotes: 4