Skip to content

Commit f5d5fb6

Browse files
authored
Mark all iterators as non-Sendable (#280)
1 parent df46b4c commit f5d5fb6

28 files changed

+138
-100
lines changed

Sources/AsyncAlgorithms/AsyncAdjacentPairsSequence.swift

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,29 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12+
extension AsyncSequence {
13+
/// An `AsyncSequence` that iterates over the adjacent pairs of the original
14+
/// original `AsyncSequence`.
15+
///
16+
/// ```
17+
/// for await (first, second) in (1...5).async.adjacentPairs() {
18+
/// print("First: \(first), Second: \(second)")
19+
/// }
20+
///
21+
/// // First: 1, Second: 2
22+
/// // First: 2, Second: 3
23+
/// // First: 3, Second: 4
24+
/// // First: 4, Second: 5
25+
/// ```
26+
///
27+
/// - Returns: An `AsyncSequence` where the element is a tuple of two adjacent elements
28+
/// or the original `AsyncSequence`.
29+
@inlinable
30+
public func adjacentPairs() -> AsyncAdjacentPairsSequence<Self> {
31+
AsyncAdjacentPairsSequence(self)
32+
}
33+
}
34+
1235
/// An `AsyncSequence` that iterates over the adjacent pairs of the original
1336
/// `AsyncSequence`.
1437
@frozen
@@ -60,29 +83,6 @@ public struct AsyncAdjacentPairsSequence<Base: AsyncSequence>: AsyncSequence {
6083
}
6184
}
6285

63-
extension AsyncSequence {
64-
/// An `AsyncSequence` that iterates over the adjacent pairs of the original
65-
/// original `AsyncSequence`.
66-
///
67-
/// ```
68-
/// for await (first, second) in (1...5).async.adjacentPairs() {
69-
/// print("First: \(first), Second: \(second)")
70-
/// }
71-
///
72-
/// // First: 1, Second: 2
73-
/// // First: 2, Second: 3
74-
/// // First: 3, Second: 4
75-
/// // First: 4, Second: 5
76-
/// ```
77-
///
78-
/// - Returns: An `AsyncSequence` where the element is a tuple of two adjacent elements
79-
/// or the original `AsyncSequence`.
80-
@inlinable
81-
public func adjacentPairs() -> AsyncAdjacentPairsSequence<Self> {
82-
AsyncAdjacentPairsSequence(self)
83-
}
84-
}
85-
8686
extension AsyncAdjacentPairsSequence: Sendable where Base: Sendable, Base.Element: Sendable { }
8787

8888
@available(*, unavailable)

Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Timer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extension AsyncTimerSequence: Sendable { }
4242
extension AsyncTimerSequence.Iterator: Sendable { }
4343
```
4444

45-
Since all the types comprising `AsyncTimerSequence` and it's `Iterator` are `Sendable` these types are also `Sendable`.
45+
Since all the types comprising `AsyncTimerSequence` are `Sendable` these types are also `Sendable`.
4646

4747
## Credits/Inspiration
4848

Sources/AsyncAlgorithms/AsyncChain3Sequence.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,6 @@ extension AsyncChain3Sequence: AsyncSequence {
9595
}
9696

9797
extension AsyncChain3Sequence: Sendable where Base1: Sendable, Base2: Sendable, Base3: Sendable { }
98+
99+
@available(*, unavailable)
100+
extension AsyncChain3Sequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/AsyncChunkedByGroupSequence.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,6 @@ public struct AsyncChunkedByGroupSequence<Base: AsyncSequence, Collected: RangeR
117117
}
118118

119119
extension AsyncChunkedByGroupSequence : Sendable where Base : Sendable, Base.Element : Sendable { }
120-
extension AsyncChunkedByGroupSequence.Iterator : Sendable where Base.AsyncIterator : Sendable, Base.Element : Sendable { }
120+
121+
@available(*, unavailable)
122+
extension AsyncChunkedByGroupSequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/AsyncChunkedOnProjectionSequence.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,6 @@ public struct AsyncChunkedOnProjectionSequence<Base: AsyncSequence, Subject: Equ
9797
}
9898

9999
extension AsyncChunkedOnProjectionSequence : Sendable where Base : Sendable, Base.Element : Sendable { }
100-
extension AsyncChunkedOnProjectionSequence.Iterator : Sendable where Base.AsyncIterator : Sendable, Base.Element : Sendable, Subject : Sendable { }
100+
101+
@available(*, unavailable)
102+
extension AsyncChunkedOnProjectionSequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/AsyncChunksOfCountOrSignalSequence.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,6 @@ public struct AsyncChunksOfCountOrSignalSequence<Base: AsyncSequence, Collected:
128128
return Iterator(iterator: merge(chain(base.map { Either.element($0) }, [.terminal].async), signal.map { _ in Either.signal }).makeAsyncIterator(), count: count)
129129
}
130130
}
131+
132+
@available(*, unavailable)
133+
extension AsyncChunksOfCountOrSignalSequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/AsyncChunksOfCountSequence.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,6 @@ public struct AsyncChunksOfCountSequence<Base: AsyncSequence, Collected: RangeRe
8383

8484
extension AsyncChunksOfCountSequence : Sendable where Base : Sendable, Base.Element : Sendable { }
8585
extension AsyncChunksOfCountSequence.Iterator : Sendable where Base.AsyncIterator : Sendable, Base.Element : Sendable { }
86+
87+
@available(*, unavailable)
88+
extension AsyncChunksOfCountSequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/AsyncCompactedSequence.swift

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12+
extension AsyncSequence {
13+
/// Returns a new `AsyncSequence` that iterates over every non-nil element from the
14+
/// original `AsyncSequence`.
15+
///
16+
/// Produces the same result as `c.compactMap { $0 }`.
17+
///
18+
/// - Returns: An `AsyncSequence` where the element is the unwrapped original
19+
/// element and iterates over every non-nil element from the original
20+
/// `AsyncSequence`.
21+
@inlinable
22+
public func compacted<Unwrapped>() -> AsyncCompactedSequence<Self, Unwrapped>
23+
where Element == Unwrapped? {
24+
AsyncCompactedSequence(self)
25+
}
26+
}
27+
1228
/// An `AsyncSequence` that iterates over every non-nil element from the original
1329
/// `AsyncSequence`.
1430
@frozen
@@ -50,22 +66,7 @@ public struct AsyncCompactedSequence<Base: AsyncSequence, Element>: AsyncSequenc
5066
}
5167
}
5268

53-
extension AsyncSequence {
54-
/// Returns a new `AsyncSequence` that iterates over every non-nil element from the
55-
/// original `AsyncSequence`.
56-
///
57-
/// Produces the same result as `c.compactMap { $0 }`.
58-
///
59-
/// - Returns: An `AsyncSequence` where the element is the unwrapped original
60-
/// element and iterates over every non-nil element from the original
61-
/// `AsyncSequence`.
62-
///
63-
/// Complexity: O(1)
64-
@inlinable
65-
public func compacted<Unwrapped>() -> AsyncCompactedSequence<Self, Unwrapped>
66-
where Element == Unwrapped? {
67-
AsyncCompactedSequence(self)
68-
}
69-
}
70-
7169
extension AsyncCompactedSequence: Sendable where Base: Sendable, Base.Element: Sendable { }
70+
71+
@available(*, unavailable)
72+
extension AsyncCompactedSequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/AsyncExclusiveReductionsSequence.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,6 @@ extension AsyncExclusiveReductionsSequence: AsyncSequence {
112112
}
113113

114114
extension AsyncExclusiveReductionsSequence: Sendable where Base: Sendable, Element: Sendable { }
115+
116+
@available(*, unavailable)
117+
extension AsyncExclusiveReductionsSequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/AsyncInclusiveReductionsSequence.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,6 @@ extension AsyncInclusiveReductionsSequence: AsyncSequence {
8585
}
8686

8787
extension AsyncInclusiveReductionsSequence: Sendable where Base: Sendable { }
88+
89+
@available(*, unavailable)
90+
extension AsyncInclusiveReductionsSequence.Iterator: Sendable { }

0 commit comments

Comments
 (0)