Michal Klimczak
10/27/2022, 6:16 AM*extension* KotlinThrowable : *@unchecked* Sendable {}
), but there are also harder cases, like passing a coroutine Job to an onCancel completion handler, like so:
var job: Kotlinx_coroutines_coreJob? = nil
let onCancel = { job?.cancel(cause: nil) }
return try await withTaskCancellationHandler(
operation: {
try await withCheckedThrowingContinuation({
(continuation: CheckedContinuation<T?, Error>) in
job = wrapper.subscribe(
onSuccess: { item in continuation.resume(returning: item) },
onThrow: { error in continuation.resume(throwing: SharedError(error)) }
)
})
},
onCancel: { onCancel() }
)