Skip to content

Instantly share code, notes, and snippets.

@jasdev

jasdev/retry_on_subject.swift Secret

Last active Apr 29, 2020
Embed
What would you like to do?
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