That's a good question. What I'd recommend for now is to use a class rather than the
suspend (Int) -> Unit
. For example:
data class SuspendFunction1Wrapper<P1: Any, Result: Any>(
private val function: (P1) -> Result,
) {
suspend fun invoke(p1: P1): Result = function(p1)
}
fun myFunc(someSwiftClosure: (kotlinFunc: SuspendFunction1Wrapper<Int, Unit>) -> Unit)
// Swift
myFunc { kotlinFunc in
Task {
try await kotlinFunc.invoke(p1: 1)
}
}
It's not perfect, but at this point I don't think there's a different way to go around it. Also keep in mind
Task { ... }
in Swift breaks cooperative concurrency (it's the same as Kotlin's
GlobalScope.launch { ... }
in this case).
I could see SKIE hiding the original implementation and replacing it with an extension function that'd replace
KotlinSuspendFunction1
with a real async lambda, but that's essentially a new SKIE feature.