Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active April 29, 2020 19:16
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/3c3319f7b8180341d3914328dff888bc to your computer and use it in GitHub Desktop.
Save jasdev/3c3319f7b8180341d3914328dff888bc to your computer and use it in GitHub Desktop.
Retrying on Subjects.
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