I’m trying to wrap some iOS code (written in swift...
# kotlin-native
j
I’m trying to wrap some iOS code (written in swift, xcode) in kotlin deferred. I’ve written this helper function:
Copy code
fun createDeferredString(context: CoroutineContext, doStuff: (() -> String)): Deferred<String> {
    return GlobalScope.async(context) {
        doStuff()
    }
}
then call it from ios app:
Copy code
func send(command: Command, data: String) -> Kotlinx_coroutines_core_nativeDeferred {
        return CoroutineHelperKt.createDeferredString(context: UI(), doStuff: {
            return "{}"
        })
    }
but get this exception:
Copy code
Uncaught Kotlin exception: kotlin.IllegalStateException: This job has not completed yet
        at 0   ios                                 0x000000010ef15106 kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception + 70
        at 1   ios                                 0x000000010ef15026 kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException + 70
        at 2   ios                                 0x000000010ef217f6 kfun:kotlin.IllegalStateException.<init>(kotlin.String?)kotlin.IllegalStateException + 70
        at 3   ios                                 0x000000010eff139a kfun:kotlinx.coroutines.JobSupport.getCompletedInternal$kotlinx-coroutines-core-native()kotlin.Any? + 330
        at 4   ios                                 0x000000010eff11f8 kfun:kotlinx.coroutines.DeferredCoroutine.getCompleted#internal + 72
any help would be very appreciated!