ghedeon
11/07/2019, 1:11 PMDispatchers.Main.immediate, what is the the best way to execute a portion immediately and launchAndForget the rest?
Ex:
suspended fun foo(){
operationA() // <--- don't wait for it, it's on IO
operationB() // <--- post on Main immediately
}
It already works if I swap the order, like
operationB() // <--- post on Main immediately
operationA() // <--- don't wait for it, it's on IO
But I'm looking for a way that doesn't depend on the order of operations.louiscad
11/07/2019, 1:29 PMCoroutineScope(…)), or GlobalScopeghedeon
11/07/2019, 2:52 PMlaunch(Dispatchers.Main.immediate){
operationA() // IO stuff
operationB() // immediate stuff
}
How to make operationB() to post on main immediately? Wrap the operationA in another coroutine scope? Didn't work unfortunatelylouiscad
11/07/2019, 3:02 PMlaunch to not wait for the completion of a child coroutinelouiscad
11/07/2019, 3:02 PMstart = CoroutineStart.UNDISPATCHED as a parameter of launch.ghedeon
11/07/2019, 3:29 PMGlobalScope.launch(Dispatchers.Main.immediate) {
coroutineScope {
launch(start = CoroutineStart.UNDISPATCHED, context = <http://Dispatchers.IO|Dispatchers.IO>) {
delay(1000)
println("third")
}
}
println("first")
}
println("second")
This prints second third firstlouiscad
11/07/2019, 3:38 PMlouiscad
11/07/2019, 3:39 PMCoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>)ghedeon
11/07/2019, 4:02 PM