Joost Klitsie
06/22/2022, 7:38 AMapplicationScope
as to make it finish, even if the original calling scope is cancelled. is the `async`/`await` the only way to do this? Or are there also other ways?withContext(applicationScope.coroutineContext) {..}
which doesn't really do the same, as if you do `withContext`and you cancel during it, then the code afterwards will still run and you'd have to do an isActive
check:
suspend fun CoroutineScope.test() {
val result = withContext(applicationScope.coroutineContext) {
delay(200)
println("producing 5")
5
}
if (!isActive) { return }
println(result)
}
Stylianos Gakis
06/28/2022, 3:02 PMCoroutineScope
does look a bit suspicious does it not?
In general if a function is an extension on CoroutineScope
I expect it to be a fire and continue, just like launch
does. Like mentioned here.
And this important quote from the Explicit Concurrency post from Elizarov:
“It leads to the following useful convention: every function that is declared as extension on CoroutineScope
returns immediately, but performs its actions concurrently with the rest of the program.”
What are you trying to achieve there Joost, I am a bit confused.Joost Klitsie
06/28/2022, 3:11 PMStylianos Gakis
06/28/2022, 3:15 PMcoroutineScope {}
function, maybe this is what you wanted to use instead?
I may be misunderstanding something, if yes you could show what you would want your code to look like which doesn’t compile and we can take it from there.Joost Klitsie
06/28/2022, 3:26 PMStylianos Gakis
06/28/2022, 3:39 PMval job = appliacationScope.launch{stuff here}; job.join()
or not even do the join part if you don’t care for waiting for it to finish.
I don’t know if you can do this without async if you want the response. If someone knows I’d love to see it.Joost Klitsie
06/29/2022, 12:09 PM