sellmair / kompass

Kotlin Multiplatform Router for Android and iOS
MIT License
345 stars 13 forks source link

Crash when creating ship from background thread #33

Closed sellmair closed 6 years ago

sellmair commented 6 years ago

When accessing a ship initially from the background thread, handelables are created by this thread where

internal interface Handleable<T> {

    @UiThread // is then called by the background thread, hence crashing
    fun handle(handler: (T) -> Unit)

    @AnyThread
    fun handle(value: T)

    companion object
}
Process: io.sellmair.there, PID: 16293
io.sellmair.kompass.internal.precondition.KompassPreconditionException: Function not called from main thread
    at io.sellmair.kompass.internal.precondition.Precondition_requireMainThreadKt.throwMainThreadRequiredException(Precondition+requireMainThread.kt:14)
    at io.sellmair.kompass.internal.precondition.Precondition_requireMainThreadKt.requireMainThread(Precondition+requireMainThread.kt:9)
    at io.sellmair.kompass.internal.pipe.HandleableImpl.handle(Handleable+delegate.kt:31)
    at io.sellmair.kompass.internal.pipe.InstructionCrane.handle(Unknown Source:7)
    at io.sellmair.kompass.internal.pipe.InstructionPipePlusConnector.<init>(InstructionPipe+plus.kt:54)
    at io.sellmair.kompass.internal.pipe.InstructionPipe_plusKt.plus(InstructionPipe+plus.kt:18)
    at io.sellmair.kompass.internal.ShipImpl.<init>(ShipImpl.kt:65)
    at io.sellmair.kompass.internal.KompassImpl.createShip(KompassImpl.kt:22)
    at io.sellmair.kompass.internal.KompassImpl.access$createShip(KompassImpl.kt:6)
    at io.sellmair.kompass.internal.KompassImpl$get$1$1.invoke(KompassImpl.kt:17)
    at io.sellmair.kompass.internal.KompassImpl$get$1$1.invoke(KompassImpl.kt:6)
    at io.sellmair.kompass.internal.util.CurryKt$curry$1.invoke(curry.kt:5)
    at io.sellmair.kompass.internal.KompassImpl.get(KompassImpl.kt:32)
    at io.sellmair.there.scenes.ShipsKt.getHome(Ships.kt:5)
    at io.sellmair.there.component.home.HomeViewModel$1.invoke(HomeViewModel.kt:19)
    at io.sellmair.there.component.home.HomeViewModel$1.invoke(HomeViewModel.kt:12)
    at io.sellmair.state.StateStoreImpl$worker$1.cycle(StateStore.kt:155)
    at io.sellmair.state.StateStoreImpl$worker$1.run(StateStore.kt:122)