Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active April 14, 2020 23:25
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/5eee18dfcadf33f4e38f6c0eb7d0c090 to your computer and use it in GitHub Desktop.
Save jasdev/5eee18dfcadf33f4e38f6c0eb7d0c090 to your computer and use it in GitHub Desktop.
Demonstrating bug with `cherReplayingLatest`.
var subscriptions = Set<AnyCancellable>()
let cheredWithReplay = Just(1)
.cherReplayingLatest()
cheredWithReplay
.sink(
receiveCompletion: { print("First completion: \($0)") },
receiveValue: { print("First sink: \($0)") }
)
.store(in: &subscriptions)
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) { /// (1) Queuing up another
/// subscription, three seconds later.
cheredWithReplay
.sink(
receiveCompletion: { print("Second completion: \($0)") },
receiveValue: { print("Second sink: \($0)") }
)
.store(in: &subscriptions)
}
/// (2) Console output:
/// ```
/// First sink: 1
/// First completion: finished
/// Second completion: finished
/// ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment