Created
July 22, 2019 16:47
-
-
Save RBusarow/aeb46e0da17ce9947c985e9062e28203 to your computer and use it in GitHub Desktop.
Example of layering CoroutineContext
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeClass : CoroutineScope { | |
val jobA = Job() | |
override val coroutineContext: CoroutineContext | |
get() = jobA + Dispatchers.Main | |
fun doSomething() { | |
// create a new coroutine using jobA and Main dispatcher | |
launch { | |
val jobB = Job() | |
// jobB and Main dispatcher | |
launch(jobB) { | |
// jobB and Default dispatcher | |
launch(Default) { } | |
} | |
// jobA and Default dispatcher | |
launch(Default) { } | |
// jobB and Default dispatcher | |
launch(jobB + Default) { } | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment