-
-
Save xbladesub/a9e3c81693bf0f1da7247b5ead553891 to your computer and use it in GitHub Desktop.
async await in combine
This file contains 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 Publisher { | |
func awaitSink(cancellable: inout Set<AnyCancellable>) async throws -> Output { | |
return try await withCheckedThrowingContinuation { continuation in | |
self.sink { completion in | |
switch completion { | |
case .finished: | |
break | |
case .failure(let error): | |
continuation.resume(with: .failure(error)) | |
} | |
} receiveValue: { result in | |
continuation.resume(with: .success(result)) | |
} | |
.store(in: &cancellable) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment