-
-
Save jasdev/5eee18dfcadf33f4e38f6c0eb7d0c090 to your computer and use it in GitHub Desktop.
Demonstrating bug with `cherReplayingLatest`.
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
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