Has someone managed to run all K/N shared code (e....
# kotlin-native
p
Has someone managed to run all K/N shared code (e.g. view models, including initialization) not in main UI thread?
t
yes, but then you can not have any mutable fields it, unless they are AtomicRef or something similar. I’d not recommend this approach
🙏 2
a
Yes, but as mentioned above, it only works well when you can avoid mutability. This means, generally speaking, architectures or codebases built around FRP/Flow and immutable data classes are the only ones that can thrive well under K/N's restrictions, in the context of multithreading.
In our case, we do run serialization*, networking**, WebSocket** and a vast majority of database transactions on background threads. Database queries (SQLDelight) are concurrently performed to fuel both UI and business logic across all threads. All managed using Kotlin Coroutines (native-mt). (* Kotlin Serialization and Apollo) (** Ktor and Apollo are main-thread bound blackboxes. So DIY for full control.)