Hello everyone, tricky coroutine context question,...
# coroutines
Hello everyone, tricky coroutine context question, will appreciate any help. I have 2 levels in my app:
Copy code
CoroutineExceptionHandler {...} + SupervisorJob() + Dispatchers.Default
Copy code
coreContext + (several custom elements holding activity reference) + Dispatchers.Main.immediate + SupervisorJob(coreContext[Job])
Let’s say I have
Copy code
// core level
class CoreModel(coreScope: CoroutineScope) {
  suspend fun operation(): Result {???}

// ui level
uiContext.launch { 
What is the correct way to implement
to run it on
Copy code
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.
Just wrapping content of operation with withContext(coreScope.coroutineContext) should be enough for this case
👍 1
Cancellation will work when uiContext.launch is cancelled
Do you really need core context in this case? Because it wouldn't cause any leak of activity in any case