Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active April 14, 2020 21:48
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 jasdev/9cade706a68844a00d160042bffce657 to your computer and use it in GitHub Desktop.
Save jasdev/9cade706a68844a00d160042bffce657 to your computer and use it in GitHub Desktop.
Proper `.cher` implementation.
extension Publisher {
func cher() -> Publishers.Autoconnect<
Publishers.Multicast<
Self,
PassthroughSubject<Output, Failure>
>
> {
multicast(PassthroughSubject.init)
.autoconnect()
}
}
var subscriptions = Set<AnyCancellable>()
Just(1)
.cher()
.sink { print($0) }
.store(in: &subscriptions)
/// (1) We’re back in `print`ing action—a `1` is logged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment