Skip to content

Instantly share code, notes, and snippets.

@Edudjr
Created February 23, 2022 02:03
Show Gist options
  • Save Edudjr/737f9a72a06f01aa407ee1116dbb440c to your computer and use it in GitHub Desktop.
Save Edudjr/737f9a72a06f01aa407ee1116dbb440c to your computer and use it in GitHub Desktop.
extension AnyPublisher {
func async() async throws -> Output {
try await withCheckedThrowingContinuation { continuation in
var cancellable: AnyCancellable?
cancellable = first()
.sink { result in
switch result {
case .finished:
break
case let .failure(error):
continuation.resume(throwing: error)
}
cancellable?.cancel()
} receiveValue: { value in
continuation.resume(with: .success(value))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment