Created
February 20, 2023 09:12
-
-
Save woodycatliu/9d14cc6d010e5ea16361236b143df3f4 to your computer and use it in GitHub Desktop.
Very few situations require only observation and no need to do anything when the signal is received
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
import Combine | |
extension Publisher { | |
public func sink(completion completionHandle: (() -> Void)? = nil, receiveError: ((Self.Failure) -> Void)? = nil, receiveValue: ((Self.Output) -> Void)? = nil) -> AnyCancellable { | |
return self.sink(receiveCompletion: { completion in | |
switch completion { | |
case .failure(let error): | |
receiveError?(error) | |
case .finished: | |
completionHandle?() | |
} | |
}, receiveValue: { value in | |
receiveValue?(value) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment