ursus
02/20/2023, 12:19 AMsuspend
functions get translated to async throws
automatically, which is neet
This however doesn't support cancellation, i.e. when swift Task
gets cancelled, the source kotlin coroutine keeps on going (In my local testing)
So, why is this. Is async
function some sort of sideffect of objc, rather than a deliberate kotlin native decision? Can I somehow influence the suspend -> async
adapter?ephemient
02/20/2023, 12:26 AMCancellation, dispatchers, coroutine context, task locals etc. are not propagated between Kotlin and Swift, they are discarded at the boundary between Kotlin and Swift.
ursus
02/20/2023, 12:29 AMephemient
02/20/2023, 12:29 AMursus
02/20/2023, 12:30 AMephemient
02/20/2023, 12:31 AMursus
02/20/2023, 12:34 AMephemient
02/20/2023, 12:43 AMursus
02/20/2023, 12:44 AMephemient
02/20/2023, 12:45 AMsuspend fun
that aren't kotlinx.coroutinesursus
02/20/2023, 12:47 AMsuspend
were stripped at the boundaryephemient
02/20/2023, 12:48 AMHowie Nguyen
02/20/2023, 12:48 AMephemient
02/20/2023, 12:48 AMursus
02/20/2023, 12:48 AMclass SuspendAdapter<T> {
private val scope = CoroutineScope(Dispatchers.Default + SupervisorJob())
fun adapt(action: suspend () -> R, onNext: () -> R) : CancellationHandle {
val job = scope.launch {
val result = action()
onNext(result)
}
return CancellationHandle(job)
}
}
nevermind you'd need a concrete FooAdapter class anyways to wrap Foo api .. so yea, codegen to generate themephemient
02/20/2023, 3:45 AM