Skip to content

Commit 6f7f1c7

Browse files
committed
Merge remote-tracking branch 'wfltaylor/async-current-value-subject-fix' into linux
2 parents 7a096ed + 29ad29a commit 6f7f1c7

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

Sources/AsyncSubjects/AsyncCurrentValueSubject.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,19 @@ public final class AsyncCurrentValueSubject<Element>: AsyncSubject where Element
9191
func handleNewConsumer() -> (iterator: AsyncBufferedChannel<Element>.Iterator, unregister: @Sendable () -> Void) {
9292
let asyncBufferedChannel = AsyncBufferedChannel<Element>()
9393

94-
let (terminalState, current) = self.state.withCriticalRegion { state in
95-
(state.terminalState, state.current)
94+
let terminalState = self.state.withCriticalRegion { state -> Termination? in
95+
state.terminalState
9696
}
9797

9898
if let terminalState = terminalState, terminalState.isFinished {
9999
asyncBufferedChannel.finish()
100100
return (asyncBufferedChannel.makeAsyncIterator(), {})
101101
}
102102

103-
asyncBufferedChannel.send(current)
104-
105103
let consumerId = self.state.withCriticalRegion { state -> Int in
106104
state.ids += 1
107105
state.channels[state.ids] = asyncBufferedChannel
106+
asyncBufferedChannel.send(state.current)
108107
return state.ids
109108
}
110109

Sources/AsyncSubjects/AsyncThrowingCurrentValueSubject.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ public final class AsyncThrowingCurrentValueSubject<Element, Failure: Error>: As
9797
) -> (iterator: AsyncThrowingBufferedChannel<Element, Error>.Iterator, unregister: @Sendable () -> Void) {
9898
let asyncBufferedChannel = AsyncThrowingBufferedChannel<Element, Error>()
9999

100-
let (terminalState, current) = self.state.withCriticalRegion { state in
101-
(state.terminalState, state.current)
100+
let terminalState = self.state.withCriticalRegion { state -> Termination? in
101+
state.terminalState
102102
}
103103

104104
if let terminalState = terminalState {
@@ -111,11 +111,10 @@ public final class AsyncThrowingCurrentValueSubject<Element, Failure: Error>: As
111111
return (asyncBufferedChannel.makeAsyncIterator(), {})
112112
}
113113

114-
asyncBufferedChannel.send(current)
115-
116114
let consumerId = self.state.withCriticalRegion { state -> Int in
117115
state.ids += 1
118116
state.channels[state.ids] = asyncBufferedChannel
117+
asyncBufferedChannel.send(state.current)
119118
return state.ids
120119
}
121120

0 commit comments

Comments
 (0)