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

darkmoon_uk

02/21/2021, 4:40 AM
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

Michal Klimczak

02/21/2021, 7:57 AM
When you use coroutines-native-mt this is exactly what you get. Dispatchers.Default performs work on a single background thread on ios
d

darkmoon_uk

02/21/2021, 11:28 AM
@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

Michal Klimczak

02/21/2021, 11:30 AM
Yep
You are right a out this dispatcher on jvm, but on native it works differently
d

darkmoon_uk

02/21/2021, 11:36 AM
Thanks so much @Michal Klimczak, this is a whole page of important documentation I'd missed on Native Coroutines; going to absorb 👍
👍 1
m

Michal Klimczak

02/21/2021, 11:36 AM
Had the same problem earlier, the docs on new stuff is everywhere and sometimes it's hard to find it
1
👍 1
21 Views