Yuri
11/09/2020, 3:37 PMCore
:
CoroutineExceptionHandler {...} + SupervisorJob() + Dispatchers.Default
UI
:
coreContext + (several custom elements holding activity reference) + Dispatchers.Main.immediate + SupervisorJob(coreContext[Job])
Let’s say I have
// core level
class CoreModel(coreScope: CoroutineScope) {
suspend fun operation(): Result {???}
}
// ui level
uiContext.launch {
showResultInUi(coreModel.operation())
}
What is the correct way to implement operation()
to run it on
coreContext with job from current coroutine (to be cancelled when UI context is cancelled) and without custom elements (to prevent activity leaks)
?
Ideally core level should know nothing about custom element’s keys.gildor
11/09/2020, 10:42 PMgildor
11/09/2020, 10:42 PMgildor
11/09/2020, 10:43 PM