Created
February 23, 2022 02:03
-
-
Save Edudjr/737f9a72a06f01aa407ee1116dbb440c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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