Skip to content

Commit ec47fbc

Browse files
committed
docs
1 parent 55b1bf0 commit ec47fbc

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

Sources/CombineExtensions/Replay.swift

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ public final class ReplaySubject<Output, Failure: Error>: Subject {
9292
let subscription = Subscription(subscriber: subscriber,
9393
buffer: buffer,
9494
bufferSize: bufferSize) { [weak self] subscription in
95-
self?.lock.lock(); defer { self?.lock.unlock() }
96-
self?.subscriptions.remove(subscription)
95+
guard let self = self else { return }
96+
self.lock.lock(); defer { self.lock.unlock() }
97+
self.subscriptions.remove(subscription)
9798
}
9899

99100
if isNotCompleted {
@@ -124,7 +125,7 @@ public final class ReplaySubject<Output, Failure: Error>: Subject {
124125
}
125126

126127
// Tells a publisher that it may send more values to the subscriber.
127-
func request(_ newDemand: Subscribers.Demand) {
128+
public func request(_ newDemand: Subscribers.Demand) {
128129
lock.lock(); defer { lock.unlock() }
129130
demand += newDemand
130131

@@ -134,11 +135,11 @@ public final class ReplaySubject<Output, Failure: Error>: Subject {
134135
}
135136
}
136137

137-
func cancel() {
138+
public func cancel() {
138139
onCancel(self)
139140
}
140141

141-
func receive(_ value: Output) {
142+
public func receive(_ value: Output) {
142143
lock.lock(); defer { lock.unlock() }
143144
if demand == .none {
144145
if bufferSize > 1 {
@@ -152,28 +153,23 @@ public final class ReplaySubject<Output, Failure: Error>: Subject {
152153
}
153154
}
154155

156+
func receive(completion: Subscribers.Completion<Failure>) {
157+
subscriber.receive(completion: completion)
158+
}
159+
155160
private func send(_ value: Output) {
156161
demand -= 1
157162
demand += subscriber.receive(value)
158163
}
159-
160-
func receive(completion: Subscribers.Completion<Failure>) {
161-
subscriber.receive(completion: completion)
162-
}
163164
}
164165
}
165166

166167
public extension Publisher {
167-
/**
168-
Returns an publisher sequence that **shares a single subscription to the underlying sequence**, and immediately upon subscription replays elements in buffer.
169-
170-
It uses optimized versions of the operators for most common operations.
171-
- parameter replay: Maximum element count of the replay buffer.
172-
- returns: A publisher sequence that contains the elements of a sequence produced by multicasting the source sequence.
173-
*/
174-
175-
/// Provides a subject that shares a single subscription to the upstream publisher and replays at most `bufferSize` items emitted by that publisher
176-
/// - Parameter bufferSize: limits the number of items that can be replayed
168+
/// Returns an publisher sequence that **shares a single subscription to the underlying sequence**,
169+
/// and immediately upon request with demand replays elements in buffer.
170+
///
171+
/// - parameter replay: Maximum element count of the replay buffer.
172+
/// - returns: A publisher sequence that contains the elements of a sequence produced by multicasting the source sequence.
177173
func share(replay: Int) -> AnyPublisher<Output, Failure> {
178174
if replay <= 0 {
179175
return share()

0 commit comments

Comments
 (0)