10
10
//===----------------------------------------------------------------------===//
11
11
@_implementationOnly import OrderedCollections
12
12
13
- struct ChannelStateMachine < Element, Failure: Error > : Sendable {
14
- private struct SuspendedProducer : Hashable {
13
+ struct OrderedSetContainer < Element: Hashable > {
14
+ var contents : OrderedSet < Element >
15
+
16
+ var isEmpty : Bool { contents. isEmpty }
17
+
18
+ mutating func removeFirst( ) -> Element {
19
+ contents. removeFirst ( )
20
+ }
21
+
22
+ mutating func remove( _ element: Element ) -> Element ? {
23
+ contents. remove ( element)
24
+ }
25
+
26
+ @discardableResult
27
+ mutating func append( _ element: Element ) -> ( inserted: Bool , index: Int ) {
28
+ contents. append ( element)
29
+ }
30
+
31
+ func map< T> ( _ apply: ( Element ) throws -> T ) rethrows -> [ T ] {
32
+ try contents. map ( apply)
33
+ }
34
+ }
35
+
36
+ extension OrderedSetContainer : ExpressibleByArrayLiteral {
37
+ typealias ArrayLiteralElement = OrderedSet < Element > . ArrayLiteralElement
38
+
39
+ init ( arrayLiteral elements: ArrayLiteralElement ... ) {
40
+ contents = OrderedSet ( elements)
41
+ }
42
+ }
43
+
44
+ extension OrderedSetContainer : @unchecked Sendable where Element: Sendable { }
45
+
46
+
47
+ struct ChannelStateMachine < Element: Sendable , Failure: Error > : Sendable {
48
+ private struct SuspendedProducer : Hashable , Sendable {
15
49
let id : UInt64
16
50
let continuation : UnsafeContinuation < Void , Never > ?
17
51
let element : Element ?
@@ -29,7 +63,7 @@ struct ChannelStateMachine<Element, Failure: Error>: Sendable {
29
63
}
30
64
}
31
65
32
- private struct SuspendedConsumer : Hashable {
66
+ private struct SuspendedConsumer : Hashable , Sendable {
33
67
let id : UInt64
34
68
let continuation : UnsafeContinuation < Element ? , any Error > ?
35
69
@@ -51,11 +85,11 @@ struct ChannelStateMachine<Element, Failure: Error>: Sendable {
51
85
case failed( Error )
52
86
}
53
87
54
- private enum State {
88
+ private enum State : Sendable {
55
89
case channeling(
56
- suspendedProducers: OrderedSet < SuspendedProducer > ,
90
+ suspendedProducers: OrderedSetContainer < SuspendedProducer > ,
57
91
cancelledProducers: Set < SuspendedProducer > ,
58
- suspendedConsumers: OrderedSet < SuspendedConsumer > ,
92
+ suspendedConsumers: OrderedSetContainer < SuspendedConsumer > ,
59
93
cancelledConsumers: Set < SuspendedConsumer >
60
94
)
61
95
case terminated( Termination )
0 commit comments