diff --git a/Sources/AsyncSubjects/AsyncCurrentValueSubject.swift b/Sources/AsyncSubjects/AsyncCurrentValueSubject.swift index 5225105..af221d4 100644 --- a/Sources/AsyncSubjects/AsyncCurrentValueSubject.swift +++ b/Sources/AsyncSubjects/AsyncCurrentValueSubject.swift @@ -91,8 +91,8 @@ public final class AsyncCurrentValueSubject: AsyncSubject where Element func handleNewConsumer() -> (iterator: AsyncBufferedChannel.Iterator, unregister: @Sendable () -> Void) { let asyncBufferedChannel = AsyncBufferedChannel() - let (terminalState, current) = self.state.withCriticalRegion { state -> (Termination?, Element) in - (state.terminalState, state.current) + let terminalState = self.state.withCriticalRegion { state -> Termination? in + state.terminalState } if let terminalState = terminalState, terminalState.isFinished { @@ -100,11 +100,10 @@ public final class AsyncCurrentValueSubject: AsyncSubject where Element return (asyncBufferedChannel.makeAsyncIterator(), {}) } - asyncBufferedChannel.send(current) - let consumerId = self.state.withCriticalRegion { state -> Int in state.ids += 1 state.channels[state.ids] = asyncBufferedChannel + asyncBufferedChannel.send(state.current) return state.ids } diff --git a/Sources/AsyncSubjects/AsyncThrowingCurrentValueSubject.swift b/Sources/AsyncSubjects/AsyncThrowingCurrentValueSubject.swift index 2294b09..1d102c0 100644 --- a/Sources/AsyncSubjects/AsyncThrowingCurrentValueSubject.swift +++ b/Sources/AsyncSubjects/AsyncThrowingCurrentValueSubject.swift @@ -97,8 +97,8 @@ public final class AsyncThrowingCurrentValueSubject: As ) -> (iterator: AsyncThrowingBufferedChannel.Iterator, unregister: @Sendable () -> Void) { let asyncBufferedChannel = AsyncThrowingBufferedChannel() - let (terminalState, current) = self.state.withCriticalRegion { state -> (Termination?, Element) in - (state.terminalState, state.current) + let terminalState = self.state.withCriticalRegion { state -> Termination? in + state.terminalState } if let terminalState = terminalState { @@ -111,11 +111,10 @@ public final class AsyncThrowingCurrentValueSubject: As return (asyncBufferedChannel.makeAsyncIterator(), {}) } - asyncBufferedChannel.send(current) - let consumerId = self.state.withCriticalRegion { state -> Int in state.ids += 1 state.channels[state.ids] = asyncBufferedChannel + asyncBufferedChannel.send(state.current) return state.ids }