@@ -13,17 +13,17 @@ import DequeModule
13
13
14
14
/// State machine for combine latest
15
15
@available ( AsyncAlgorithms 1 . 1 , * )
16
- struct CombineLatestManyStateMachine < Element: Sendable > : Sendable {
16
+ struct CombineLatestManyStateMachine < Element: Sendable , Failure : Error > : Sendable {
17
17
typealias DownstreamContinuation = UnsafeContinuation <
18
- Result < [ Element ] ? , Error > , Never
18
+ Result < [ Element ] ? , Failure > , Never
19
19
>
20
- typealias Base = AsyncSequence < Element , any Error > & Sendable
20
+ typealias Base = AsyncSequence < Element , Failure > & Sendable
21
21
22
22
private enum State : Sendable {
23
23
/// Small wrapper for the state of an upstream sequence.
24
24
struct Upstream : Sendable {
25
25
/// The upstream continuation.
26
- var continuation : UnsafeContinuation < Void , Error > ?
26
+ var continuation : UnsafeContinuation < Void , Never > ?
27
27
/// The produced upstream element.
28
28
var element : Element ?
29
29
/// Indicates wether the upstream finished/threw already
@@ -53,7 +53,7 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
53
53
)
54
54
55
55
case upstreamThrew(
56
- error: Error
56
+ error: Failure
57
57
)
58
58
59
59
/// The state once the downstream consumer stopped, i.e. by dropping all references
@@ -77,10 +77,10 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
77
77
/// Actions returned by `iteratorDeinitialized()`.
78
78
enum IteratorDeinitializedAction {
79
79
/// 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 `.
81
81
case cancelTaskAndUpstreamContinuations(
82
82
task: Task < Void , Never > ,
83
- upstreamContinuations: [ UnsafeContinuation < Void , Error > ]
83
+ upstreamContinuations: [ UnsafeContinuation < Void , Never > ]
84
84
)
85
85
}
86
86
@@ -151,18 +151,13 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
151
151
enum ChildTaskSuspendedAction {
152
152
/// Indicates that the continuation should be resumed which will lead to calling `next` on the upstream.
153
153
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 >
160
155
)
161
156
}
162
157
163
158
mutating func childTaskSuspended(
164
159
baseIndex: Int ,
165
- continuation: UnsafeContinuation < Void , Error >
160
+ continuation: UnsafeContinuation < Void , Never >
166
161
) -> ChildTaskSuspendedAction ? {
167
162
switch self . state {
168
163
case . initial:
@@ -193,9 +188,8 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
193
188
// Since cancellation is cooperative it might be that child tasks are still getting
194
189
// suspended even though we already cancelled them. We must tolerate this and just resume
195
190
// the continuation with an error.
196
- return . resumeContinuationWithError(
197
- upstreamContinuation: continuation,
198
- error: CancellationError ( )
191
+ return . resumeContinuation(
192
+ upstreamContinuation: continuation
199
193
)
200
194
201
195
case . modifying:
@@ -208,7 +202,7 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
208
202
/// Indicates that the downstream continuation should be resumed with the element.
209
203
case resumeContinuation(
210
204
downstreamContinuation: DownstreamContinuation ,
211
- result: Result < [ Element ] ? , Error >
205
+ result: Result < [ Element ] ? , Failure >
212
206
)
213
207
}
214
208
@@ -293,14 +287,14 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
293
287
/// Indicates the task and the upstream continuations should be cancelled.
294
288
case cancelTaskAndUpstreamContinuations(
295
289
task: Task < Void , Never > ,
296
- upstreamContinuations: [ UnsafeContinuation < Void , Error > ]
290
+ upstreamContinuations: [ UnsafeContinuation < Void , Never > ]
297
291
)
298
292
/// Indicates that the downstream continuation should be resumed with `nil` and
299
293
/// the task and the upstream continuations should be cancelled.
300
294
case resumeContinuationWithNilAndCancelTaskAndUpstreamContinuations(
301
295
downstreamContinuation: DownstreamContinuation ,
302
296
task: Task < Void , Never > ,
303
- upstreamContinuations: [ UnsafeContinuation < Void , Error > ]
297
+ upstreamContinuations: [ UnsafeContinuation < Void , Never > ]
304
298
)
305
299
}
306
300
@@ -394,19 +388,19 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
394
388
/// Indicates the task and the upstream continuations should be cancelled.
395
389
case cancelTaskAndUpstreamContinuations(
396
390
task: Task < Void , Never > ,
397
- upstreamContinuations: [ UnsafeContinuation < Void , Error > ]
391
+ upstreamContinuations: [ UnsafeContinuation < Void , Never > ]
398
392
)
399
393
/// Indicates that the downstream continuation should be resumed with the `error` and
400
394
/// the task and the upstream continuations should be cancelled.
401
- case resumeContinuationWithErrorAndCancelTaskAndUpstreamContinuations (
395
+ case resumeContinuationWithFailureAndCancelTaskAndUpstreamContinuations (
402
396
downstreamContinuation: DownstreamContinuation ,
403
- error: Error ,
397
+ error: Failure ,
404
398
task: Task < Void , Never > ,
405
- upstreamContinuations: [ UnsafeContinuation < Void , Error > ]
399
+ upstreamContinuations: [ UnsafeContinuation < Void , Never > ]
406
400
)
407
401
}
408
402
409
- mutating func upstreamThrew( _ error: Error ) -> UpstreamThrewAction ? {
403
+ mutating func upstreamThrew( _ error: Failure ) -> UpstreamThrewAction ? {
410
404
switch self . state {
411
405
case . initial:
412
406
preconditionFailure ( " Internal inconsistency current state \( self . state) and received upstreamThrew() " )
@@ -433,7 +427,7 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
433
427
// the upstream work.
434
428
self . state = . finished
435
429
436
- return . resumeContinuationWithErrorAndCancelTaskAndUpstreamContinuations (
430
+ return . resumeContinuationWithFailureAndCancelTaskAndUpstreamContinuations (
437
431
downstreamContinuation: downstreamContinuation,
438
432
error: error,
439
433
task: task,
@@ -456,12 +450,12 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
456
450
case resumeDownstreamContinuationWithNilAndCancelTaskAndUpstreamContinuations(
457
451
downstreamContinuation: DownstreamContinuation ,
458
452
task: Task < Void , Never > ,
459
- upstreamContinuations: [ UnsafeContinuation < Void , Error > ]
453
+ upstreamContinuations: [ UnsafeContinuation < Void , Never > ]
460
454
)
461
455
/// Indicates that the task and the upstream continuations should be cancelled.
462
456
case cancelTaskAndUpstreamContinuations(
463
457
task: Task < Void , Never > ,
464
- upstreamContinuations: [ UnsafeContinuation < Void , Error > ]
458
+ upstreamContinuations: [ UnsafeContinuation < Void , Never > ]
465
459
)
466
460
}
467
461
@@ -515,12 +509,12 @@ struct CombineLatestManyStateMachine<Element: Sendable>: Sendable {
515
509
case startTask( [ any Base ] )
516
510
/// Indicates that all upstream continuations should be resumed.
517
511
case resumeUpstreamContinuations(
518
- upstreamContinuation: [ UnsafeContinuation < Void , Error > ]
512
+ upstreamContinuation: [ UnsafeContinuation < Void , Never > ]
519
513
)
520
514
/// Indicates that the downstream continuation should be resumed with the result.
521
515
case resumeContinuation(
522
516
downstreamContinuation: DownstreamContinuation ,
523
- result: Result < [ Element ] ? , Error >
517
+ result: Result < [ Element ] ? , Failure >
524
518
)
525
519
/// Indicates that the downstream continuation should be resumed with `nil`.
526
520
case resumeDownstreamContinuationWithNil( DownstreamContinuation )
0 commit comments