I’m using Kotlin-Native with native-mt coroutine s...
# multiplatform
c
I’m using Kotlin-Native with native-mt coroutine support and the ktor library. I have several suspended functions that take in an object built using a builder pattern. I understand I need to call the suspended function on the main/ui thread. However, I can’t guarantee that the builder objects will be created on that thread. My understanding is they would need to be frozen before sending them to the main thread to be called with the suspended function. Is that correct? For instance, this would fail because the
query
object hasn’t been frozen:
Copy code
func loadData() {
        DispatchQueue.global(qos: .background).async {
            let query = CustomerQuery().emails(value: ["<mailto:customer@gmail.com|customer@gmail.com>"])
            self.fetchCustomersAndDoSomething(query: query)
        }
    }
    
    func fetchCustomersAndDoSomething(query: CustomerQuery) {
        DispatchQueue.main.async {
            self.mylibrary.getCustomers(query: query) { response, err in
                // do something with response
            }
        }
    }
If that’s true, it would seem I would need to add a method to every such object in order to ‘freeze’ it, since the
freeze()
Kotlin function from
Freezing.kt
doesn’t seem to be accessible from the Swift code importing my library.