Last active
March 1, 2022 19:52
-
-
Save Monntay/b5cf7a29383e55283f128b6376947a75 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