Has someone managed to run all K/N shared code (e.g. view models, including initialization) not in main UI thread?
t
Tijl
05/06/2021, 10:14 AM
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
Anders
05/07/2021, 11:07 PM
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.
Anders
05/07/2021, 11:23 PM
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.)