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.
ephemient
02/20/2023, 12:28 AMursus
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 AMephemient
02/20/2023, 12:43 AMursus
02/20/2023, 12:44 AMursus
02/20/2023, 12:44 AMephemient
02/20/2023, 12:45 AMephemient
02/20/2023, 12:46 AMsuspend fun that aren't kotlinx.coroutinesursus
02/20/2023, 12:47 AMursus
02/20/2023, 12:47 AMsuspend were stripped at the boundaryephemient
02/20/2023, 12:48 AMHowie Nguyen
02/20/2023, 12:48 AMHowie Nguyen
02/20/2023, 12:48 AMephemient
02/20/2023, 12:48 AMursus
02/20/2023, 12:48 AMursus
02/20/2023, 12:49 AMursus
02/20/2023, 12:50 AMursus
02/20/2023, 12:52 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 themursus
02/20/2023, 12:52 AMephemient
02/20/2023, 3:45 AM