Skip to content

Instantly share code, notes, and snippets.

@jasdev
Created April 17, 2020 16:01
Show Gist options
  • Save jasdev/5ea990ff464fe626ca48cae59da18cdd to your computer and use it in GitHub Desktop.
Save jasdev/5ea990ff464fe626ca48cae59da18cdd to your computer and use it in GitHub Desktop.
`cherReplayingLatest` ⇒ `share(replay: 1)`.
let sharedWithReplay = Just(1)
.share(replay: 1) /// (1) Swapping in `share(replay: 1)` for `cherReplayingLatest`.
sharedWithReplay
.sink(
receiveCompletion: { print("First completion: \($0)") },
receiveValue: { print("First sink: \($0)") }
)
.store(in: &subscriptions)
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) {
sharedWithReplay
.sink(
receiveCompletion: { print("Second completion: \($0)") },
receiveValue: { print("Second sink: \($0)") }
)
.store(in: &subscriptions)
}
/// Console output: (2) We got back a value event on the second sink!
/// ```
/// First sink: 1
/// First completion: finished
/// Second sink: 1
/// Second completion: finished
/// ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment