julioromano
06/25/2021, 8:51 AMsuspend fun myFunction(myParam: String): Unit = myScope.launch {
doSomethingElseSuspending()
withContext(anotherContext) { doSomeOtherStuffInTheOtherContext(myParam) }
}.join()
The rationale is that the caller of myFunction
should not care of what’s happening inside it, the caller merely calls a suspending function (myFunction()
) that suspends until all work done inside it is done and then either throws or returns Unit.bezrukov
06/25/2021, 9:10 AMsuspend fun myFunction(myParam: String) {
doSomethingElseSuspending()
withContext(anotherContext) { doSomeOtherStuffInTheOtherContext(myParam) }
}
bezrukov
06/25/2021, 9:12 AMjulioromano
06/25/2021, 9:38 AMif outer scope is cancelled, cancellation won’t be propagated to launched coroutine via joinThat was the purpose: whatever
myFunction
does should keep on going if the the outer scope is cancelled.
In addition myScope
has a SupervisorJob
and CoroutineExceptionHandler
in it so that if anything inside myFunction
throws the exception will be propagated via other means by the Handler.Justin Tullgren
06/29/2021, 7:20 PMjulioromano
06/30/2021, 6:22 AM