This is my current code for implementing Dispatche...
# kotlin-native
b
This is my current code for implementing Dispatchers in KN (coroutines-core:1.3.6) for iOS. Has anybody been able to define a dispatcher in commonMain code only? Also, has Kotlinx been able to execute tasks on iOS background threads yet?
Copy code
actual val Main: CoroutineDispatcher = NsQueueDispatcher(dispatch_get_main_queue())

actual val Background: CoroutineDispatcher = Main

internal class NsQueueDispatcher(
    private val dispatchQueue: dispatch_queue_t
) : CoroutineDispatcher() {
    override fun dispatch(context: CoroutineContext, block: Runnable) {
        dispatch_async(dispatchQueue) {
            block.run()
        }
    }
}
t
I would upgrade to 1.4.2-native-mt, then you have
Dispatchers.Main
and
Dispatchers.Default
/
newSingleThreadContext
for background