mirror of
https://github.com/apple/swift-async-algorithms
synced 2026-11-25 04:27:48 +00:00
Audit pass on Sendable conformances and requirements (#272)
* Audit pass on Sendable conformances and requirements * A slightly cleaner mark for Sendability of OrderedSet * Remove flags for strict mode
This commit is contained in:
1 parent
156bb4bf49
commit
a42b72ad84
7 files changed
+19
-10
No files matched your search
+1
-1
@@ -16,7 +16,7 @@ let package = Package(
|
||||
.library(name: "_CAsyncSequenceValidationSupport", type: .static, targets: ["AsyncSequenceValidation"]),
|
||||
.library(name: "AsyncAlgorithms_XCTest", targets: ["AsyncAlgorithms_XCTest"]),
|
||||
],
|
||||
dependencies: [.package(url: "https://github.com/apple/swift-collections.git", .upToNextMajor(from: "1.0.3"))],
|
||||
dependencies: [.package(url: "https://github.com/apple/swift-collections.git", .upToNextMajor(from: "1.0.4"))],
|
||||
targets: [
|
||||
.target(
|
||||
name: "AsyncAlgorithms",
|
||||
|
||||
@@ -16,7 +16,7 @@ struct BoundedBufferStateMachine<Base: AsyncSequence> {
|
||||
typealias SuspendedProducer = UnsafeContinuation<Void, Never>
|
||||
typealias SuspendedConsumer = UnsafeContinuation<Result<Base.Element, Error>?, Never>
|
||||
|
||||
private enum State {
|
||||
fileprivate enum State {
|
||||
case initial(base: Base)
|
||||
case buffering(
|
||||
task: Task<Void, Never>,
|
||||
@@ -308,3 +308,6 @@ struct BoundedBufferStateMachine<Base: AsyncSequence> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension BoundedBufferStateMachine: Sendable where Base: Sendable { }
|
||||
extension BoundedBufferStateMachine.State: Sendable where Base: Sendable { }
|
||||
@@ -21,7 +21,7 @@ struct UnboundedBufferStateMachine<Base: AsyncSequence> {
|
||||
case bufferingOldest(Int)
|
||||
}
|
||||
|
||||
private enum State {
|
||||
fileprivate enum State {
|
||||
case initial(base: Base)
|
||||
case buffering(
|
||||
task: Task<Void, Never>,
|
||||
@@ -248,3 +248,6 @@ struct UnboundedBufferStateMachine<Base: AsyncSequence> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension UnboundedBufferStateMachine: Sendable where Base: Sendable { }
|
||||
extension UnboundedBufferStateMachine.State: Sendable where Base: Sendable { }
|
||||
@@ -19,7 +19,7 @@
|
||||
/// on the `Iterator` is made, or when `finish()` is called from another Task.
|
||||
/// As `finish()` induces a terminal state, there is no more need for a back pressure management.
|
||||
/// This function does not suspend and will finish all the pending iterations.
|
||||
public final class AsyncChannel<Element>: AsyncSequence, @unchecked Sendable {
|
||||
public final class AsyncChannel<Element: Sendable>: AsyncSequence, @unchecked Sendable {
|
||||
public typealias Element = Element
|
||||
public typealias AsyncIterator = Iterator
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
/// and is resumed when the next call to `next()` on the `Iterator` is made, or when `finish()`/`fail(_:)` is called
|
||||
/// from another Task. As `finish()` and `fail(_:)` induce a terminal state, there is no more need for a back pressure management.
|
||||
/// Those functions do not suspend and will finish all the pending iterations.
|
||||
public final class AsyncThrowingChannel<Element, Failure: Error>: AsyncSequence, @unchecked Sendable {
|
||||
public final class AsyncThrowingChannel<Element: Sendable, Failure: Error>: AsyncSequence, @unchecked Sendable {
|
||||
public typealias Element = Element
|
||||
public typealias AsyncIterator = Iterator
|
||||
|
||||
|
||||
@@ -10,8 +10,11 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
@_implementationOnly import OrderedCollections
|
||||
|
||||
struct ChannelStateMachine<Element, Failure: Error>: Sendable {
|
||||
private struct SuspendedProducer: Hashable {
|
||||
// NOTE: this is only marked as unchecked since the swift-collections tag is before auditing for Sendable
|
||||
extension OrderedSet: @unchecked Sendable where Element: Sendable { }
|
||||
|
||||
struct ChannelStateMachine<Element: Sendable, Failure: Error>: Sendable {
|
||||
private struct SuspendedProducer: Hashable, Sendable {
|
||||
let id: UInt64
|
||||
let continuation: UnsafeContinuation<Void, Never>?
|
||||
let element: Element?
|
||||
@@ -29,7 +32,7 @@ struct ChannelStateMachine<Element, Failure: Error>: Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
private struct SuspendedConsumer: Hashable {
|
||||
private struct SuspendedConsumer: Hashable, Sendable {
|
||||
let id: UInt64
|
||||
let continuation: UnsafeContinuation<Element?, any Error>?
|
||||
|
||||
@@ -51,7 +54,7 @@ struct ChannelStateMachine<Element, Failure: Error>: Sendable {
|
||||
case failed(Error)
|
||||
}
|
||||
|
||||
private enum State {
|
||||
private enum State: Sendable {
|
||||
case channeling(
|
||||
suspendedProducers: OrderedSet<SuspendedProducer>,
|
||||
cancelledProducers: Set<SuspendedProducer>,
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
struct ChannelStorage<Element, Failure: Error>: Sendable {
|
||||
struct ChannelStorage<Element: Sendable, Failure: Error>: Sendable {
|
||||
private let stateMachine: ManagedCriticalState<ChannelStateMachine<Element, Failure>>
|
||||
private let ids = ManagedCriticalState<UInt64>(0)
|
||||
|
||||
|
||||
Reference in new issue
Block a user