https://kotlinlang.org logo
Title
h

hfhbd

05/18/2023, 11:49 AM
On JVM there is a ThreadContextElement. What is the equivalent for Kotlin Native? Use-case: I want to create a fixed thread pool (newFixedThreadPoolContext), but each thread (Worker) needs to have a unique resource (a database connection). Or is this impossible because there is no Kotlin native coroutine support/implementation? For example: https://github.com/Kotlin/kotlinx.coroutines/blob/9582584cf308edbb923f5dec772cf06c417d782b/kotlinx-coroutines-core/jvm/src/CoroutineContext.kt#L106 contains the JVM thread updating/restoring, while on native this method ignore the coroutine context: https://github.com/Kotlin/kotlinx.coroutines/blob/9582584cf308edbb923f5dec772cf06c417d782b/kotlinx-coroutines-core/native/src/CoroutineContext.kt#L46
p

Patrick Steiger

05/18/2023, 11:56 AM
Not sure but I don’t believe it’s available https://github.com/Kotlin/kotlinx.coroutines/issues/3326
h

hfhbd

05/18/2023, 12:06 PM
Thanks for the link, I am just curious if this would be the right approach at all. I took a look at Exposed and it uses ThreadContextElement, because it is jvm only. I like the implementation to pass the db conn, which need to be connected to the thread/worker, using coroutine context elements.