https://kotlinlang.org logo
#coroutines
Title
# coroutines
j

Jan Groen

08/29/2021, 9:19 PM
Hey o/ I'm trying to implement the coroutines library on a JVM-based gaming platform. I was wondering if there is a possibilty to implement the
Dispatchers.Main
dispatcher (other than using the
ServiceLoader
). This would be useful, because a lot of the data needs to be updated from the main game loop. I'm aware that I could create my own dispatcher and I have done that. I just think that it would be more ideomatic if I could use the
Dispatchers.Main
Dispatcher.
a

Astronaut4449

08/29/2021, 10:11 PM
I think there is a
setMainDispatcher
function or similar. I think it is often used in unit tests.
But what's the problem with the service loader?
e

ephemient

08/29/2021, 10:33 PM
setMainDispatcher is only in the kotlinx-coroutines-test package, changing what its service loader returns
but yeah, why not service loader?
j

Jan Groen

08/29/2021, 10:35 PM
I was just wondering if there was an officially supported way. The
MainDispatcherFactory
is marked as
InternalCoroutinesApi
.
e

elizarov

08/31/2021, 8:35 AM
Not public at the moment, but your use-case is quite compelling to stabilize this SPI. Please, file an issue to https://github.com/Kotlin/kotlinx.coroutines/issues
3 Views