Martin Rajniak
03/11/2022, 3:42 PMsuspend
function).
But this is not possible if I understand correctly:
Calling Kotlin suspend functions from Swift/Objective-C is currently supported only on main threadI am using Kotlin 1.6.10, Coroutines 1.6.0 (without
native-mt
) and new experimental memory model.
Is the current practice to leave threading to multi-platform code or am I missing something?russhwolf
03/11/2022, 4:53 PMMartin Rajniak
03/11/2022, 5:12 PMMike Wolfson
03/11/2022, 6:38 PMhfhbd
03/11/2022, 7:46 PMRick Clephas
03/16/2022, 7:50 AMAny good examples?That would depend on your needs. You could define a fairly simple wrapper that does the same as the default completion handler version, or you can write a wrapper that fully supports coroutines (with cancellation). I actually created a library for the full support version: https://github.com/rickclephas/KMP-NativeCoroutines. With the following Kotlin wrapper for suspend functions: https://github.com/rickclephas/KMP-NativeCoroutines/blob/9a9a18086f093126a218057b3434b8ceafef2e2f/kmp-nativecoroutines-core/src/nativeCoroutinesMain/kotlin/com/rickclephas/kmp/nativecoroutines/NativeSuspend.kt
Martin Rajniak
03/16/2022, 7:55 AMRick Clephas
03/16/2022, 8:00 AMException
if it somehow reaches Kotlin again (it will just wrap it into an exception instead).
There are some technical limitations that prevent the interop logic from being used in app/library code: https://youtrack.jetbrains.com/issue/KT-50539
I do however have a POC that exposes this logic: https://github.com/rickclephas/NSErrorKtMartin Rajniak
03/16/2022, 8:02 AM