Dariusz Kuc
12/11/2020, 4:45 PMsuspend fun doWork() = coroutineScope {
val result = ...
// do some other processing that calculates/processes result
publishData(result) // optional stuff that may be slow, e.g. publish analytics, debug info, etc
result
}
Thanks to structured concurrency if I launch another coroutine from the doWork
, all the child coroutines (including publishData
from above) have to complete before returning from the scope. I could obviously just do GlobalScope.launch { publishData }
but that seems “wrong”.
Wondering whether instead I should be using something like buffered Channel
so publish is async and data is processed in another coroutine. Or maybe there is something simpler?Zach Klippenstein (he/him) [MOD]
12/11/2020, 4:47 PMDariusz Kuc
12/11/2020, 5:01 PMZach Klippenstein (he/him) [MOD]
12/11/2020, 5:37 PMDariusz Kuc
12/11/2020, 5:56 PM