Skip to content

Instantly share code, notes, and snippets.

@woodycatliu
Created February 20, 2023 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woodycatliu/9d14cc6d010e5ea16361236b143df3f4 to your computer and use it in GitHub Desktop.
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
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