Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active April 20, 2020 15:44
Show Gist options
  • Save jasdev/776d54edcdcaf8d634cd4322cea33291 to your computer and use it in GitHub Desktop.
Save jasdev/776d54edcdcaf8d634cd4322cea33291 to your computer and use it in GitHub Desktop.
`ReplaySubject` with filled-in `.send(subscription:)` requirement.
final class ReplaySubject<Output, Failure: Error>: Subject {
typealias Output = Output
typealias Failure = Failure
private let bufferSize: Int
init(bufferSize: Int) {
self.bufferSize = bufferSize
}
func send(subscription: Combine.Subscription) {
subscription.request(.unlimited)
}
func send(completion: Subscribers.Completion<Failure>) { /* … */ }
func send(_ value: Output) { /* … */ }
func receive<Subscriber: Combine.Subscriber>(
subscriber: Subscriber
) where Failure == Subscriber.Failure, Output == Subscriber.Input { /* … */ }
}
extension ReplaySubject {
final class Subscription: Combine.Subscription {
func request(_ demand: Subscribers.Demand) { /* … */ }
func cancel() { /* … */ }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment