in mobius-coroutines/src/main/java/com/spotify/mobius/coroutines/CoroutinesSubtypeEffectHandlerBuilder.kt [256:280]
override fun accept(effect: F) {
scope.launch {
val subEffectChannel = mutex.withLock {
// Prevents the creation of an effectChannel if the scope is not active
if(!isActive) return@launch
subEffectChannelsMap.getOrPut(effect::class) {
// Creates an effectChannel the first time the effect is processed
val subEffectChannel = Channel<F>()
val effectHandler = effectsHandlersMap[effect::class]
?: error("No effectHandler for $effect")
// Connects the effectHandler the first time the effect is processed
scope.launch {
if (isActive) effectHandler.handleEffects(
subEffectChannel, eventsChannel
)
}
subEffectChannel
}
}
// Prevents the processing of the effect if the scope is not active
if (isActive) subEffectChannel.send(effect)
}
}