Last active
April 20, 2020 15:55
-
-
Save jasdev/66820d1ae07ebde49f8683fb6473b251 to your computer and use it in GitHub Desktop.
`ReplaySubject.Subscription` with `DemandBuffer`.
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
final class ReplaySubject<Output, Failure: Error>: Subject { /* … */ } | |
extension ReplaySubject { | |
final class Subscription<Subscriber: Combine.Subscriber>: Combine.Subscription | |
where Subscriber.Input == Output, Subscriber.Failure == Failure { | |
private var buffer: DemandBuffer<Subscriber>? | |
fileprivate let innerSubscriberIdentifier: CombineIdentifier | |
init(subscriber: Subscriber) { | |
buffer = DemandBuffer(subscriber: subscriber) | |
innerSubscriberIdentifier = subscriber.combineIdentifier | |
} | |
func request(_ demand: Subscribers.Demand) { | |
_ = buffer?.demand(demand) | |
} | |
func cancel() { | |
buffer = nil | |
} | |
func forward(completion: Subscribers.Completion<Failure>) { | |
buffer?.complete(completion: completion) | |
} | |
func forward(value: Output) { | |
_ = buffer?.buffer(value: value) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment