What is the best/official way to write a custom Ma...
# coroutines
g
What is the best/official way to write a custom MainCoroutineDispatcher? I wrote one for SWT but requires use of internal and experimental API
m
If you're on the JVM, you could just create a new
Executor
with the
Executors
API (https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executors.html), and then convert it to a dispatcher with the
asCoroutineDispatcher
extension.
If you need it to be the main-dispatcher, I guess you need to somehow register it to a ServiceLoader, like the other main-dispatchers (https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-main.html)
g
This doesn't give me a MainCoroutineDispatcher
I made it work but I wonder if there is a better way without internal/experimental api. the way via ServiceLoader smells
v
There are no official ways to write a custom dispatcher that will be available via
Dispatchers.Main
g
there should be. It is quite handy if you write code for different platforms. Android and desktop (SWT) in my case
v
Could you please file an issue on github with your use-case?
g
👍🏻
🙏 1