How can I create a single threaded Dispatcher on K...
# coroutines
d
How can I create a single threaded Dispatcher on Kotlin Native for iOS (that isn't the Main Dispatcher)? I want to keep business logic off the Main thread but also not worry about state being frozen between threads, which is a pitfall when using the Default Dispatcher (on a multi core device). A two-threaded delineation between UI/business logic seems like a more manageable, pragmatic middle ground for KMM projects until the new Native Memory model changes the landscape.
m
When you use coroutines-native-mt this is exactly what you get. Dispatchers.Default performs work on a single background thread on ios
d
@Michal Klimczak Can you cite this? My understanding of
Dispatchers.Default
is that it typically uses a Thread count equal to the number of hardware cores available on the platform. I know this isn't a guarantee, but neither have I seen it stated anywhere that the Default Dispatcher of
coroutines-native-mt
is Single threaded.
m
Yep
You are right a out this dispatcher on jvm, but on native it works differently
d
Thanks so much @Michal Klimczak, this is a whole page of important documentation I'd missed on Native Coroutines; going to absorb 👍
👍 1
m
Had the same problem earlier, the docs on new stuff is everywhere and sometimes it's hard to find it
1
👍 1