@@ -13,17 +13,17 @@ import DequeModule
1313
1414/// State machine for combine latest
1515@available ( AsyncAlgorithms 1 . 1 , * )
16- struct CombineLatestManyStateMachine < Element: Sendable > : Sendable {
16+ struct CombineLatestManyStateMachine < Element: Sendable , Failure : Error > : Sendable {
1717 typealias DownstreamContinuation = UnsafeContinuation <
18- Result < [ Element ] ? , Error > , Never
18+ Result < [ Element ] ? , Failure > , Never
1919 >
20- typealias Base = AsyncSequence < Element , any Error > & Sendable
20+ typealias Base = AsyncSequence < Element , Failure > & Sendable
2121
2222 private enum State : Sendable {
2323 /// Small wrapper for the state of an upstream sequence.
2424 struct Upstream : Sendable {
2525 /// The upstream continuation.
26- var continuation : UnsafeContinuation < Void , Error > ?
26+ var continuation : UnsafeContinuation < Void , Never > ?
2727 /// The produced upstream element.
2828 var element : Element ?
2929 /// Indicates wether the upstream finished/threw already
@@ -53,7 +53,7 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
5353 )
5454
5555 case upstreamThrew(
56- error: Error
56+ error: Failure
5757 )
5858
5959 /// The state once the downstream consumer stopped, i.e. by dropping all references
@@ -77,10 +77,10 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
7777 /// Actions returned by `iteratorDeinitialized()`.
7878 enum IteratorDeinitializedAction {
7979 /// Indicates that the `Task` needs to be cancelled and
80- /// the upstream continuations need to be resumed with a `CancellationError `.
80+ /// the upstream continuations need to be resumed with a `CancellationFailure `.
8181 case cancelTaskAndUpstreamContinuations(
8282 task: Task < Void , Never > ,
83- upstreamContinuations: [ UnsafeContinuation < Void , Error > ]
83+ upstreamContinuations: [ UnsafeContinuation < Void , Never > ]
8484 )
8585 }
8686
@@ -151,18 +151,13 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
151151 enum ChildTaskSuspendedAction {
152152 /// Indicates that the continuation should be resumed which will lead to calling `next` on the upstream.
153153 case resumeContinuation(
154- upstreamContinuation: UnsafeContinuation < Void , Error >
155- )
156- /// Indicates that the continuation should be resumed with an Error because another upstream sequence threw.
157- case resumeContinuationWithError(
158- upstreamContinuation: UnsafeContinuation < Void , Error > ,
159- error: Error
154+ upstreamContinuation: UnsafeContinuation < Void , Never >
160155 )
161156 }
162157
163158 mutating func childTaskSuspended(
164159 baseIndex: Int ,
165- continuation: UnsafeContinuation < Void , Error >
160+ continuation: UnsafeContinuation < Void , Never >
166161 ) -> ChildTaskSuspendedAction ? {
167162 switch self . state {
168163 case . initial:
@@ -193,9 +188,8 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
193188 // Since cancellation is cooperative it might be that child tasks are still getting
194189 // suspended even though we already cancelled them. We must tolerate this and just resume
195190 // the continuation with an error.
196- return . resumeContinuationWithError(
197- upstreamContinuation: continuation,
198- error: CancellationError ( )
191+ return . resumeContinuation(
192+ upstreamContinuation: continuation
199193 )
200194
201195 case . modifying:
@@ -208,7 +202,7 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
208202 /// Indicates that the downstream continuation should be resumed with the element.
209203 case resumeContinuation(
210204 downstreamContinuation: DownstreamContinuation ,
211- result: Result < [ Element ] ? , Error >
205+ result: Result < [ Element ] ? , Failure >
212206 )
213207 }
214208
@@ -293,14 +287,14 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
293287 /// Indicates the task and the upstream continuations should be cancelled.
294288 case cancelTaskAndUpstreamContinuations(
295289 task: Task < Void , Never > ,
296- upstreamContinuations: [ UnsafeContinuation < Void , Error > ]
290+ upstreamContinuations: [ UnsafeContinuation < Void , Never > ]
297291 )
298292 /// Indicates that the downstream continuation should be resumed with `nil` and
299293 /// the task and the upstream continuations should be cancelled.
300294 case resumeContinuationWithNilAndCancelTaskAndUpstreamContinuations(
301295 downstreamContinuation: DownstreamContinuation ,
302296 task: Task < Void , Never > ,
303- upstreamContinuations: [ UnsafeContinuation < Void , Error > ]
297+ upstreamContinuations: [ UnsafeContinuation < Void , Never > ]
304298 )
305299 }
306300
@@ -394,19 +388,19 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
394388 /// Indicates the task and the upstream continuations should be cancelled.
395389 case cancelTaskAndUpstreamContinuations(
396390 task: Task < Void , Never > ,
397- upstreamContinuations: [ UnsafeContinuation < Void , Error > ]
391+ upstreamContinuations: [ UnsafeContinuation < Void , Never > ]
398392 )
399393 /// Indicates that the downstream continuation should be resumed with the `error` and
400394 /// the task and the upstream continuations should be cancelled.
401- case resumeContinuationWithErrorAndCancelTaskAndUpstreamContinuations (
395+ case resumeContinuationWithFailureAndCancelTaskAndUpstreamContinuations (
402396 downstreamContinuation: DownstreamContinuation ,
403- error: Error ,
397+ error: Failure ,
404398 task: Task < Void , Never > ,
405- upstreamContinuations: [ UnsafeContinuation < Void , Error > ]
399+ upstreamContinuations: [ UnsafeContinuation < Void , Never > ]
406400 )
407401 }
408402
409- mutating func upstreamThrew( _ error: Error ) -> UpstreamThrewAction ? {
403+ mutating func upstreamThrew( _ error: Failure ) -> UpstreamThrewAction ? {
410404 switch self . state {
411405 case . initial:
412406 preconditionFailure ( " Internal inconsistency current state \( self . state) and received upstreamThrew() " )
@@ -433,7 +427,7 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
433427 // the upstream work.
434428 self . state = . finished
435429
436- return . resumeContinuationWithErrorAndCancelTaskAndUpstreamContinuations (
430+ return . resumeContinuationWithFailureAndCancelTaskAndUpstreamContinuations (
437431 downstreamContinuation: downstreamContinuation,
438432 error: error,
439433 task: task,
@@ -456,12 +450,12 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
456450 case resumeDownstreamContinuationWithNilAndCancelTaskAndUpstreamContinuations(
457451 downstreamContinuation: DownstreamContinuation ,
458452 task: Task < Void , Never > ,
459- upstreamContinuations: [ UnsafeContinuation < Void , Error > ]
453+ upstreamContinuations: [ UnsafeContinuation < Void , Never > ]
460454 )
461455 /// Indicates that the task and the upstream continuations should be cancelled.
462456 case cancelTaskAndUpstreamContinuations(
463457 task: Task < Void , Never > ,
464- upstreamContinuations: [ UnsafeContinuation < Void , Error > ]
458+ upstreamContinuations: [ UnsafeContinuation < Void , Never > ]
465459 )
466460 }
467461
@@ -515,12 +509,12 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
515509 case startTask( [ any Base ] )
516510 /// Indicates that all upstream continuations should be resumed.
517511 case resumeUpstreamContinuations(
518- upstreamContinuation: [ UnsafeContinuation < Void , Error > ]
512+ upstreamContinuation: [ UnsafeContinuation < Void , Never > ]
519513 )
520514 /// Indicates that the downstream continuation should be resumed with the result.
521515 case resumeContinuation(
522516 downstreamContinuation: DownstreamContinuation ,
523- result: Result < [ Element ] ? , Error >
517+ result: Result < [ Element ] ? , Failure >
524518 )
525519 /// Indicates that the downstream continuation should be resumed with `nil`.
526520 case resumeDownstreamContinuationWithNil( DownstreamContinuation )
0 commit comments