@@ -45,37 +45,33 @@ public final class AsyncThrowingReplaySubject<Element, Failure: Error>: AsyncSub
4545 /// Sends a value to all consumers
4646 /// - Parameter element: the value to send
4747 public func send( _ element: Element ) {
48- let channels = self . state. withCriticalRegion { state -> [ AsyncThrowingBufferedChannel < Element , Error > ] in
48+ self . state. withCriticalRegion { state in
4949 if state. buffer. count >= state. bufferSize && !state. buffer. isEmpty {
5050 state. buffer. removeFirst ( )
5151 }
5252 state. buffer. append ( element)
53- return Array ( state. channels. values)
54- }
55-
56- for channel in channels {
57- channel. send ( element)
53+ for channel in state. channels. values {
54+ channel. send ( element)
55+ }
5856 }
5957 }
6058
6159 /// Finishes the subject with either a normal ending or an error.
6260 /// - Parameter termination: The termination to finish the subject
6361 public func send( _ termination: Termination < Failure > ) {
64- let channels = self . state. withCriticalRegion { state -> [ AsyncThrowingBufferedChannel < Element , Error > ] in
62+ self . state. withCriticalRegion { state in
6563 state. terminalState = termination
6664 let channels = Array ( state. channels. values)
6765 state. channels. removeAll ( )
6866 state. buffer. removeAll ( )
6967 state. bufferSize = 0
70- return channels
71- }
72-
73- for channel in channels {
74- switch termination {
75- case . finished:
76- channel. finish ( )
77- case . failure( let error) :
78- channel. fail ( error)
68+ for channel in channels {
69+ switch termination {
70+ case . finished:
71+ channel. finish ( )
72+ case . failure( let error) :
73+ channel. fail ( error)
74+ }
7975 }
8076 }
8177 }
@@ -134,10 +130,10 @@ public final class AsyncThrowingReplaySubject<Element, Failure: Error>: AsyncSub
134130 }
135131
136132 public mutating func next( ) async throws -> Element ? {
137- try await withTaskCancellationHandler { [ unregister] in
138- unregister ( )
139- } operation: {
133+ try await withTaskCancellationHandler {
140134 try await self . iterator. next ( )
135+ } onCancel: { [ unregister] in
136+ unregister ( )
141137 }
142138 }
143139 }
0 commit comments