-
-
Save jasdev/3c3319f7b8180341d3914328dff888bc to your computer and use it in GitHub Desktop.
Retrying on Subjects.
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
import Combine | |
var subscriptions = Set<AnyCancellable>() | |
enum SomeError: Error { /// (1) inb4 rogue code review, this is for sake of example. | |
case anError | |
} | |
let subject = PassthroughSubject<Int, SomeError>() | |
subject | |
.retry(1) /// (2) The key bit. | |
.sink( | |
receiveCompletion: { print($0) }, | |
receiveValue: { print($0) } | |
) | |
.store(in: &subscriptions) | |
subject.send(1) | |
subject.send(2) | |
subject.send(3) | |
subject.send(completion: .failure(.anError)) | |
subject.send(4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment