diff --git a/Sources/AsyncAlgorithms/AsyncBufferedByteIterator.swift b/Sources/AsyncAlgorithms/AsyncBufferedByteIterator.swift index a16d4a7..66377f7 100644 --- a/Sources/AsyncAlgorithms/AsyncBufferedByteIterator.swift +++ b/Sources/AsyncAlgorithms/AsyncBufferedByteIterator.swift @@ -67,17 +67,13 @@ public struct AsyncBufferedByteIterator: AsyncIteratorProtocol, Sendable { @frozen @usableFromInline internal struct _AsyncBytesBuffer: @unchecked Sendable { @usableFromInline - final class Storage { - fileprivate let readFunction: @Sendable (UnsafeMutableRawBufferPointer) async throws -> Int + final class Storage: Sendable { fileprivate let buffer: UnsafeMutableRawBufferPointer - fileprivate var finished = false init( - capacity: Int, - readFunction: @Sendable @escaping (UnsafeMutableRawBufferPointer) async throws -> Int + capacity: Int ) { precondition(capacity > 0) - self.readFunction = readFunction buffer = UnsafeMutableRawBufferPointer.allocate( byteCount: capacity, alignment: MemoryLayout.alignment @@ -93,11 +89,15 @@ internal struct _AsyncBytesBuffer: @unchecked Sendable { @usableFromInline internal var nextPointer: UnsafeRawPointer @usableFromInline internal var endPointer: UnsafeRawPointer + internal let readFunction: @Sendable (UnsafeMutableRawBufferPointer) async throws -> Int + internal var finished = false + @usableFromInline init( capacity: Int, readFunction: @Sendable @escaping (UnsafeMutableRawBufferPointer) async throws -> Int ) { - let s = Storage(capacity: capacity, readFunction: readFunction) + let s = Storage(capacity: capacity) + self.readFunction = readFunction storage = s nextPointer = UnsafeRawPointer(s.buffer.baseAddress!) endPointer = nextPointer @@ -105,21 +105,21 @@ internal struct _AsyncBytesBuffer: @unchecked Sendable { @inline(never) @usableFromInline internal mutating func reloadBufferAndNext() async throws -> UInt8? { - if storage.finished { + if finished { return nil } try Task.checkCancellation() do { - let readSize: Int = try await storage.readFunction(storage.buffer) + let readSize: Int = try await readFunction(storage.buffer) if readSize == 0 { - storage.finished = true + finished = true nextPointer = endPointer return nil } nextPointer = UnsafeRawPointer(storage.buffer.baseAddress!) endPointer = nextPointer + readSize } catch { - storage.finished = true + finished = true nextPointer = endPointer throw error } diff --git a/Sources/AsyncAlgorithms/AsyncCombineLatest3Sequence.swift b/Sources/AsyncAlgorithms/AsyncCombineLatest3Sequence.swift index 0748567..a0ee829 100644 --- a/Sources/AsyncAlgorithms/AsyncCombineLatest3Sequence.swift +++ b/Sources/AsyncAlgorithms/AsyncCombineLatest3Sequence.swift @@ -13,7 +13,7 @@ public func combineLatest +public struct AsyncCombineLatest3Sequence: Sendable where Base1: Sendable, Base2: Sendable, Base3: Sendable, Base1.Element: Sendable, Base2.Element: Sendable, Base3.Element: Sendable, @@ -32,7 +32,7 @@ public struct AsyncCombineLatest3Sequence, Base3>.Iterator init(_ base1: Base1.AsyncIterator, _ base2: Base2.AsyncIterator, _ base3: Base3.AsyncIterator) { diff --git a/Sources/AsyncSequenceValidation/Expectation.swift b/Sources/AsyncSequenceValidation/Expectation.swift index 9872d91..c67beb4 100644 --- a/Sources/AsyncSequenceValidation/Expectation.swift +++ b/Sources/AsyncSequenceValidation/Expectation.swift @@ -10,13 +10,13 @@ //===----------------------------------------------------------------------===// extension AsyncSequenceValidationDiagram { - public struct ExpectationResult { + public struct ExpectationResult: Sendable { public var expected: [(Clock.Instant, Result)] public var actual: [(Clock.Instant, Result)] } - public struct ExpectationFailure: CustomStringConvertible { - public enum Kind { + public struct ExpectationFailure: Sendable, CustomStringConvertible { + public enum Kind: Sendable { case expectedFinishButGotValue(String) case expectedMismatch(String, String) case expectedValueButGotFinished(String) diff --git a/Sources/AsyncSequenceValidation/Input.swift b/Sources/AsyncSequenceValidation/Input.swift index efc616a..5013307 100644 --- a/Sources/AsyncSequenceValidation/Input.swift +++ b/Sources/AsyncSequenceValidation/Input.swift @@ -21,7 +21,7 @@ extension AsyncSequenceValidationDiagram { let queue: WorkQueue let index: Int - public struct Iterator: AsyncIteratorProtocol { + public struct Iterator: AsyncIteratorProtocol, Sendable { let state: ManagedCriticalState let queue: WorkQueue let index: Int diff --git a/Sources/AsyncSequenceValidation/Theme.swift b/Sources/AsyncSequenceValidation/Theme.swift index 2fe7ce0..59fc107 100644 --- a/Sources/AsyncSequenceValidation/Theme.swift +++ b/Sources/AsyncSequenceValidation/Theme.swift @@ -20,7 +20,7 @@ extension AsyncSequenceValidationTheme where Self == AsyncSequenceValidationDiag } extension AsyncSequenceValidationDiagram { - public enum Token { + public enum Token: Sendable { case step case error case finish @@ -34,7 +34,7 @@ extension AsyncSequenceValidationDiagram { case value(String) } - public struct ASCIITheme: AsyncSequenceValidationTheme { + public struct ASCIITheme: AsyncSequenceValidationTheme, Sendable { public func token(_ character: Character, inValue: Bool) -> AsyncSequenceValidationDiagram.Token { switch character { case "-": return .step diff --git a/Tests/AsyncAlgorithmsTests/TestValidator.swift b/Tests/AsyncAlgorithmsTests/TestValidator.swift index 9c5ef9c..2b4a152 100644 --- a/Tests/AsyncAlgorithmsTests/TestValidator.swift +++ b/Tests/AsyncAlgorithmsTests/TestValidator.swift @@ -9,7 +9,7 @@ // //===----------------------------------------------------------------------===// -import XCTest +@preconcurrency import XCTest import AsyncAlgorithms final class TestValidator: XCTestCase {