Is there a way to convert Worker to coroutineDispa...
# kotlin-native
b
Is there a way to convert Worker to coroutineDispatcher/Context? I need to ensure that the callback from coroutine job is executed on the same thread that launched the coroutine
k
You can go the other way. Create a single worker dispatcher and get it’s worker. This assumes you’re using the newer multithreaded coroutines branch and preview. https://github.com/Kotlin/kotlinx.coroutines/blob/native-mt/kotlin-native-sharing.md “For interoperability with code that is using Kotlin/Native Worker API you can get a reference to single-threaded dispacher’s worker using its SingleThreadDispatcher.worker property.”
b
Unfortunately i need to be on the main thread for the callback execution (linux). Dispatchers.Main doeasn't help here.
k
I haven’t done any of this with linux, so probably won’t be of much help
b
Windows, maybe?
As I'm targeting both with GTK+
k
No. For native and coroutines I’ve only done apple stuff, which has a main thread baked into the runtime
b
Looks like you can get main thread dispatcher in the main method via run blocking
Copy code
val mainDispatcher = runBlocking {
        coroutineContext[ContinuationInterceptor]
                as CoroutineDispatcher}