Hello everyone, tricky coroutine context question, will appreciate any help.
I have 2 levels in my app:
Core
:
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.