What is working way to have static class, that wil...
# kotlin-native
k
What is working way to have static class, that will work in kotlin native (ios, different threads)? I want to avoid passing references to some objects inside kotlin code.
o
If object is mutable - there’s no way, and it is generally considered bad style. If it is not mutable and is frozen - it could be stored in a global variable
k
Is there some example with kotlin code called from multiple threads?
o
yes, see https://github.com/JetBrains/kotlin-native/pull/1686 for example of shared frozen object, and in general
globalState
sample for various approaches of accessing same state across threads. Please, beware that it is rather subtle matter, and requires careful thinking before publishing state between threads.
k
thank you!