From 82698abf316d261fb4c70a105d96f53254e1718f Mon Sep 17 00:00:00 2001 From: George Barnett Date: Mon, 28 Apr 2025 10:29:40 +0100 Subject: [PATCH] Add explicit sendability annotations Motivation: As part of adopting strict concurrency all public types should be explicit about whether they are sendable or not. Modifications: - Add explicit sendability annotations to a number of types Result: Sendability is explicit --- Sources/AsyncHTTPClient/AsyncAwait/AnyAsyncSequence.swift | 3 +++ Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse.swift | 6 ++++++ .../AsyncAwait/Transaction+StateMachine.swift | 3 +++ Sources/AsyncHTTPClient/Base64.swift | 2 +- Sources/AsyncHTTPClient/Utils.swift | 4 ++-- 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Sources/AsyncHTTPClient/AsyncAwait/AnyAsyncSequence.swift b/Sources/AsyncHTTPClient/AsyncAwait/AnyAsyncSequence.swift index 8f6b32bd2..fbcc82ec1 100644 --- a/Sources/AsyncHTTPClient/AsyncAwait/AnyAsyncSequence.swift +++ b/Sources/AsyncHTTPClient/AsyncAwait/AnyAsyncSequence.swift @@ -46,3 +46,6 @@ struct AnyAsyncSequence: Sendable, AsyncSequence { .init(nextCallback: self.makeAsyncIteratorCallback()) } } + +@available(*, unavailable) +extension AnyAsyncSequence.AsyncIterator: Sendable {} diff --git a/Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse.swift b/Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse.swift index fa29e6de4..36c1cb36f 100644 --- a/Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse.swift +++ b/Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse.swift @@ -259,3 +259,9 @@ extension HTTPClientResponse.Body { .stream(CollectionOfOne(byteBuffer).async) } } + +@available(*, unavailable) +extension HTTPClientResponse.Body.AsyncIterator: Sendable {} + +@available(*, unavailable) +extension HTTPClientResponse.Body.Storage.AsyncIterator: Sendable {} diff --git a/Sources/AsyncHTTPClient/AsyncAwait/Transaction+StateMachine.swift b/Sources/AsyncHTTPClient/AsyncAwait/Transaction+StateMachine.swift index 6cf0dbc07..457627a8a 100644 --- a/Sources/AsyncHTTPClient/AsyncAwait/Transaction+StateMachine.swift +++ b/Sources/AsyncHTTPClient/AsyncAwait/Transaction+StateMachine.swift @@ -552,3 +552,6 @@ extension Transaction { } } } + +@available(*, unavailable) +extension Transaction.StateMachine: Sendable {} diff --git a/Sources/AsyncHTTPClient/Base64.swift b/Sources/AsyncHTTPClient/Base64.swift index 3162e7251..4d2ddcc49 100644 --- a/Sources/AsyncHTTPClient/Base64.swift +++ b/Sources/AsyncHTTPClient/Base64.swift @@ -29,7 +29,7 @@ extension String { // swift-format-ignore: DontRepeatTypeInStaticProperties @usableFromInline -internal struct Base64 { +internal struct Base64: Sendable { @inlinable static func encode( diff --git a/Sources/AsyncHTTPClient/Utils.swift b/Sources/AsyncHTTPClient/Utils.swift index abdd5bbc2..985755143 100644 --- a/Sources/AsyncHTTPClient/Utils.swift +++ b/Sources/AsyncHTTPClient/Utils.swift @@ -18,10 +18,10 @@ import NIOCore /// /// ``HTTPClientCopyingDelegate`` discards most parts of a HTTP response, but streams the body /// to the `chunkHandler` provided on ``init(chunkHandler:)``. This is mostly useful for testing. -public final class HTTPClientCopyingDelegate: HTTPClientResponseDelegate { +public final class HTTPClientCopyingDelegate: HTTPClientResponseDelegate, Sendable { public typealias Response = Void - let chunkHandler: (ByteBuffer) -> EventLoopFuture + let chunkHandler: @Sendable (ByteBuffer) -> EventLoopFuture @preconcurrency public init(chunkHandler: @Sendable @escaping (ByteBuffer) -> EventLoopFuture) {