Skip to content

Commit 9d6ffd3

Browse files
committed
Feedback
1 parent f08df01 commit 9d6ffd3

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

Sources/ComposableArchitecture/Internal/CurrentValueRelay.swift

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,14 @@ final class CurrentValueRelay<Output>: Publisher {
5353
extension CurrentValueRelay {
5454
fileprivate final class Subscription: Combine.Subscription, Equatable {
5555
private var demand = Subscribers.Demand.none
56-
57-
private var _downstream: (any Subscriber<Output, Never>)?
58-
private var downstream: (any Subscriber<Output, Never>)? {
59-
var downstream: (any Subscriber<Output, Never>)?
60-
self.lock.sync { downstream = _downstream }
61-
return downstream
62-
}
63-
56+
private var downstream: (any Subscriber<Output, Never>)?
6457
private let lock: os_unfair_lock_t
6558
private var receivedLastValue = false
6659
private var upstream: CurrentValueRelay?
6760

6861
init(upstream: CurrentValueRelay, downstream: any Subscriber<Output, Never>) {
6962
self.upstream = upstream
70-
self._downstream = downstream
63+
self.downstream = downstream
7164
self.lock = os_unfair_lock_t.allocate(capacity: 1)
7265
self.lock.initialize(to: os_unfair_lock())
7366
}
@@ -79,16 +72,20 @@ extension CurrentValueRelay {
7972

8073
func cancel() {
8174
self.lock.sync {
82-
self._downstream = nil
75+
self.downstream = nil
8376
self.upstream?.remove(self)
8477
self.upstream = nil
8578
}
8679
}
8780

8881
func receive(_ value: Output) {
89-
guard let downstream else { return }
90-
9182
self.lock.lock()
83+
84+
guard let downstream else {
85+
self.lock.unlock()
86+
return
87+
}
88+
9289
switch self.demand {
9390
case .unlimited:
9491
self.lock.unlock()
@@ -113,9 +110,13 @@ extension CurrentValueRelay {
113110
func request(_ demand: Subscribers.Demand) {
114111
precondition(demand > 0, "Demand must be greater than zero")
115112

116-
guard let downstream else { return }
117-
118113
self.lock.lock()
114+
115+
guard let downstream else {
116+
self.lock.unlock()
117+
return
118+
}
119+
119120
self.demand += demand
120121

121122
guard

0 commit comments

Comments
 (0)