Hello 👋 I was just wondering what is the idiomatic way to launch some side effects from main coroutine whose return value doesn’t depend on it (i.e. side effect can take some time to complete and it is fine if that computation fail) so that it actually does not have to wait for its completion, e.g. given something simple like below
suspend 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?