Skip to content

Commit 37fd4d5

Browse files
committed
A slightly cleaner mark for Sendability of OrderedSet
1 parent 428d8d1 commit 37fd4d5

File tree

1 file changed

+4
-35
lines changed

1 file changed

+4
-35
lines changed

Sources/AsyncAlgorithms/Channels/ChannelStateMachine.swift

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,8 @@
1010
//===----------------------------------------------------------------------===//
1111
@_implementationOnly import OrderedCollections
1212

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-
13+
// NOTE: this is only marked as unchecked since the swift-collections tag is before auditing for Sendable
14+
extension OrderedSet: @unchecked Sendable where Element: Sendable { }
4615

4716
struct ChannelStateMachine<Element: Sendable, Failure: Error>: Sendable {
4817
private struct SuspendedProducer: Hashable, Sendable {
@@ -87,9 +56,9 @@ struct ChannelStateMachine<Element: Sendable, Failure: Error>: Sendable {
8756

8857
private enum State: Sendable {
8958
case channeling(
90-
suspendedProducers: OrderedSetContainer<SuspendedProducer>,
59+
suspendedProducers: OrderedSet<SuspendedProducer>,
9160
cancelledProducers: Set<SuspendedProducer>,
92-
suspendedConsumers: OrderedSetContainer<SuspendedConsumer>,
61+
suspendedConsumers: OrderedSet<SuspendedConsumer>,
9362
cancelledConsumers: Set<SuspendedConsumer>
9463
)
9564
case terminated(Termination)

0 commit comments

Comments
 (0)