vivid-money / elmslie

Kotlin TEA/ELM implementation with first class android support
https://github.com/vivid-money/elmslie
Apache License 2.0
116 stars 13 forks source link

fix Switcher + rewrite one example #199

Closed rcmkt closed 1 year ago

rcmkt commented 1 year ago

When the flow inside Switcher throws exceptions sometimes it may cancel the whole scope and this error is not handling by mapEvents method. This leads to unexpected behavior and loose events for reducing. It can be reproduced in the sample app from this repository (coroutines-loader).

The exception which can be thrown and breaks the flow:

at vivid.money.elmslie.samples.coroutines.timer.elm.TimerActor$secondsFlow$1.invokeSuspend(TimerActor.kt:31)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
        Suppressed: kotlinx.coroutines.JobCancellationException: ScopeCoroutine is cancelling; job=ScopeCoroutine{Cancelled}@96cd3f7
        [CIRCULAR REFERENCE:java.lang.IllegalStateException: Test error]

Also, refresh one of the samples to use actual API + show the way of passing arguments to the store