Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active April 20, 2020 15:41
Show Gist options
  • Save jasdev/47fc9498b591a87a864d98c2ac4f4c1a to your computer and use it in GitHub Desktop.
Save jasdev/47fc9498b591a87a864d98c2ac4f4c1a to your computer and use it in GitHub Desktop.
`ReplaySubject` and `.Subscription` scaffolding.
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) { /// (1) We’ll need to fully qualify `Combine.Subscription` to
/// make it clear to the compiler–if this extra step isn’t your cup of tea, it’s also totally valid to name the
/// types something else.
/* … */
}
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 { /// (2) Same note as `(1)`.
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