Is there a good project/example of using Backgroun...
# multiplatform
l
Is there a good project/example of using BackgroundTask to trigger a function from shared module? Our efforts end up with Uncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: illegal attempt to access non-shared org.koin.core.context.GlobalContext.KoinInstanceHolder@82f9b368 from other thread. Apparently, our shared Model, which is a KoinComponent, gets frozen, when we use Model.getProgress() in the ios background task, if I understand it correctly
t
Since the error message mentions Koin, I can say that I’ve experienced issues on iOS when lazily injecting dependencies using Koin (AKA
by inject()
) and changing coroutine dispatchers. I don’t fully understand what the issue is, but I observed that instantiating the
KoinComponent
on one thread and resolving the dependency in another thread causes trouble. The ways to avoid trouble that I’ve used are: • Eagerly resolve dependencies in shared code by using
get()
instead of
by inject()
. Or: • Making sure that dependency resolution happens on the same thread that the
KoinComponent
is instantiated on.