Tristan
07/30/2021, 4:56 PMclass IosDispatcher : CoroutineDispatcher() {
override fun dispatch(context: CoroutineContext, block: Runnable) {
dispatch_async(dispatch_get_main_queue()) { block.run() }
}
}
actual class PrimaryScope : CoroutineScope {
private val dispatcher = IosDispatcher()
private val job = Job()
override val coroutineContext: CoroutineContext
get() = dispatcher + job
}
fun <T>observe(origin: Flow<T>, block: (T) -> Unit): PrimaryScope {
val scope = PrimaryScope()
origin.onEach {
block(it)
}.launchIn(scope)
return scope
}
But when I do use it, I am getting the error from the screenshot.
I use it like this (I tried with empty block in case it was related to a reference lost, or similar):
[UnityKotlinCoroutineHelperKt observeOrigin: self.tokenStorage.events
block:^(id result) {
}];
Do you have some example I could use? Or article explaining how to achieve this? Thanks a lot for your lights.mkrussel
07/30/2021, 5:26 PMTristan
07/30/2021, 7:52 PMmkrussel
07/30/2021, 7:53 PMnative-mt
version and accessing the dispatcher from a background thread, but not sure.Tristan
07/31/2021, 2:40 AM