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 { }

Sources/AsyncAlgorithms/AsyncJoinedBySeparatorSequence.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,6 @@ public struct AsyncJoinedBySeparatorSequence<Base: AsyncSequence, Separator: Asy
142142

143143
extension AsyncJoinedBySeparatorSequence: Sendable
144144
where Base: Sendable, Base.Element: Sendable, Base.Element.Element: Sendable, Separator: Sendable { }
145+
146+
@available(*, unavailable)
147+
extension AsyncJoinedBySeparatorSequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/AsyncJoinedSequence.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,6 @@ public struct AsyncJoinedSequence<Base: AsyncSequence>: AsyncSequence where Base
9292

9393
extension AsyncJoinedSequence: Sendable
9494
where Base: Sendable, Base.Element: Sendable, Base.Element.Element: Sendable { }
95+
96+
@available(*, unavailable)
97+
extension AsyncJoinedSequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/AsyncRemoveDuplicatesSequence.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,9 @@ public struct AsyncThrowingRemoveDuplicatesSequence<Base: AsyncSequence>: AsyncS
143143

144144
extension AsyncRemoveDuplicatesSequence: Sendable where Base: Sendable, Base.Element: Sendable { }
145145
extension AsyncThrowingRemoveDuplicatesSequence: Sendable where Base: Sendable, Base.Element: Sendable { }
146+
147+
@available(*, unavailable)
148+
extension AsyncRemoveDuplicatesSequence.Iterator: Sendable { }
149+
150+
@available(*, unavailable)
151+
extension AsyncThrowingRemoveDuplicatesSequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/AsyncSyncSequence.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,6 @@ public struct AsyncSyncSequence<Base: Sequence>: AsyncSequence {
6767
}
6868

6969
extension AsyncSyncSequence: Sendable where Base: Sendable { }
70+
71+
@available(*, unavailable)
72+
extension AsyncSyncSequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/AsyncThrottleSequence.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,6 @@ extension AsyncThrottleSequence: AsyncSequence {
102102

103103
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
104104
extension AsyncThrottleSequence: Sendable where Base: Sendable, Element: Sendable { }
105+
106+
@available(*, unavailable)
107+
extension AsyncThrottleSequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/AsyncThrowingExclusiveReductionsSequence.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,6 @@ extension AsyncThrowingExclusiveReductionsSequence: AsyncSequence {
119119
}
120120

121121
extension AsyncThrowingExclusiveReductionsSequence: Sendable where Base: Sendable, Element: Sendable { }
122+
123+
@available(*, unavailable)
124+
extension AsyncThrowingExclusiveReductionsSequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/AsyncThrowingInclusiveReductionsSequence.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift Async Algorithms open source project
4+
//
5+
// Copyright (c) 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
//
10+
//===----------------------------------------------------------------------===//
11+
112
extension AsyncSequence {
213
/// Returns an asynchronous sequence containing the accumulated results of combining the
314
/// elements of the asynchronous sequence using the given error-throwing closure.
@@ -89,3 +100,6 @@ extension AsyncThrowingInclusiveReductionsSequence: AsyncSequence {
89100
}
90101

91102
extension AsyncThrowingInclusiveReductionsSequence: Sendable where Base: Sendable { }
103+
104+
@available(*, unavailable)
105+
extension AsyncThrowingInclusiveReductionsSequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/AsyncTimerSequence.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,6 @@ extension AsyncTimerSequence where C == SuspendingClock {
8989

9090
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
9191
extension AsyncTimerSequence: Sendable { }
92+
93+
@available(*, unavailable)
94+
extension AsyncTimerSequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/Channels/AsyncChannel.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ public final class AsyncChannel<Element: Sendable>: AsyncSequence, @unchecked Se
5858
}
5959
}
6060
}
61+
62+
@available(*, unavailable)
63+
extension AsyncChannel.Iterator: Sendable { }

Sources/AsyncAlgorithms/Channels/AsyncThrowingChannel.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,6 @@ public final class AsyncThrowingChannel<Element: Sendable, Failure: Error>: Asyn
6161
}
6262
}
6363
}
64+
65+
@available(*, unavailable)
66+
extension AsyncThrowingChannel.Iterator: Sendable { }

Sources/AsyncAlgorithms/CombineLatest/AsyncCombineLatest2Sequence.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,6 @@ public struct AsyncCombineLatest2Sequence<
8787
}
8888
}
8989
}
90+
91+
@available(*, unavailable)
92+
extension AsyncCombineLatest2Sequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/CombineLatest/AsyncCombineLatest3Sequence.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,6 @@ public struct AsyncCombineLatest3Sequence<
9797
}
9898
}
9999
}
100+
101+
@available(*, unavailable)
102+
extension AsyncCombineLatest3Sequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/Debounce/AsyncDebounceSequence.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,20 @@ public struct AsyncDebounceSequence<Base: AsyncSequence, C: Clock>: Sendable whe
5353
extension AsyncDebounceSequence: AsyncSequence {
5454
public typealias Element = Base.Element
5555

56-
public func makeAsyncIterator() -> AsyncIterator {
56+
public func makeAsyncIterator() -> Iterator {
5757
let storage = DebounceStorage(
5858
base: self.base,
5959
interval: self.interval,
6060
tolerance: self.tolerance,
6161
clock: self.clock
6262
)
63-
return AsyncIterator(storage: storage)
63+
return Iterator(storage: storage)
6464
}
6565
}
6666

6767
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
6868
extension AsyncDebounceSequence {
69-
public struct AsyncIterator: AsyncIteratorProtocol {
69+
public struct Iterator: AsyncIteratorProtocol {
7070
/// This class is needed to hook the deinit to observe once all references to the ``AsyncIterator`` are dropped.
7171
///
7272
/// If we get move-only types we should be able to drop this class and use the `deinit` of the ``AsyncIterator`` struct itself.
@@ -97,3 +97,6 @@ extension AsyncDebounceSequence {
9797
}
9898
}
9999
}
100+
101+
@available(*, unavailable)
102+
extension AsyncDebounceSequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/Merge/AsyncMerge2Sequence.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ public struct AsyncMerge2Sequence<
5050
}
5151

5252
extension AsyncMerge2Sequence: AsyncSequence {
53-
public func makeAsyncIterator() -> AsyncIterator {
53+
public func makeAsyncIterator() -> Iterator {
5454
let storage = MergeStorage<Base1, Base2, Base1>(
5555
base1: base1,
5656
base2: base2,
5757
base3: nil
5858
)
59-
return AsyncIterator(storage: storage)
59+
return Iterator(storage: storage)
6060
}
6161
}
6262

6363
extension AsyncMerge2Sequence {
64-
public struct AsyncIterator: AsyncIteratorProtocol {
64+
public struct Iterator: AsyncIteratorProtocol {
6565
/// This class is needed to hook the deinit to observe once all references to the ``AsyncIterator`` are dropped.
6666
///
6767
/// If we get move-only types we should be able to drop this class and use the `deinit` of the ``AsyncIterator`` struct itself.
@@ -92,3 +92,6 @@ extension AsyncMerge2Sequence {
9292
}
9393
}
9494
}
95+
96+
@available(*, unavailable)
97+
extension AsyncMerge2Sequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/Merge/AsyncMerge3Sequence.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ public struct AsyncMerge3Sequence<
6161
}
6262

6363
extension AsyncMerge3Sequence: AsyncSequence {
64-
public func makeAsyncIterator() -> AsyncIterator {
64+
public func makeAsyncIterator() -> Iterator {
6565
let storage = MergeStorage(
6666
base1: base1,
6767
base2: base2,
6868
base3: base3
6969
)
70-
return AsyncIterator(storage: storage)
70+
return Iterator(storage: storage)
7171
}
7272
}
7373

7474
public extension AsyncMerge3Sequence {
75-
struct AsyncIterator: AsyncIteratorProtocol {
75+
struct Iterator: AsyncIteratorProtocol {
7676
/// This class is needed to hook the deinit to observe once all references to the ``AsyncIterator`` are dropped.
7777
///
7878
/// If we get move-only types we should be able to drop this class and use the `deinit` of the ``AsyncIterator`` struct itself.
@@ -103,3 +103,6 @@ public extension AsyncMerge3Sequence {
103103
}
104104
}
105105
}
106+
107+
@available(*, unavailable)
108+
extension AsyncMerge3Sequence.Iterator: Sendable { }

0 commit comments

Comments
 (0)