Browse Source

Start adding explicit Sendability.

Jon Shier 3 years ago
parent
commit
912b228290
3 changed files with 19 additions and 4 deletions
  1. 6 4
      Source/Concurrency.swift
  2. 5 0
      Source/Request.swift
  3. 8 0
      Source/Response.swift

+ 6 - 4
Source/Concurrency.swift

@@ -23,6 +23,7 @@
 //
 
 #if compiler(>=5.6.0) && canImport(_Concurrency)
+// swiftformat:options --swiftversion 5.6
 
 import Foundation
 
@@ -112,7 +113,7 @@ extension Request {
 
 /// Value used to `await` a `DataResponse` and associated values.
 @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
-public struct DataTask<Value> {
+public struct DataTask<Value: Sendable>: Sendable {
     /// `DataResponse` produced by the `DataRequest` and its response handler.
     public var response: DataResponse<Value, AFError> {
         get async {
@@ -283,7 +284,7 @@ extension DataRequest {
     }
 
     private func dataTask<Value>(automaticallyCancelling shouldAutomaticallyCancel: Bool,
-                                 forResponse onResponse: @escaping (@escaping (DataResponse<Value, AFError>) -> Void) -> Void)
+                                 forResponse onResponse: @Sendable @escaping (@escaping (DataResponse<Value, AFError>) -> Void) -> Void)
         -> DataTask<Value> {
         let task = Task {
             await withTaskCancellationHandler {
@@ -305,7 +306,7 @@ extension DataRequest {
 
 /// Value used to `await` a `DownloadResponse` and associated values.
 @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
-public struct DownloadTask<Value> {
+public struct DownloadTask<Value: Sendable>: Sendable {
     /// `DownloadResponse` produced by the `DownloadRequest` and its response handler.
     public var response: DownloadResponse<Value, AFError> {
         get async {
@@ -492,7 +493,7 @@ extension DownloadRequest {
     }
 
     private func downloadTask<Value>(automaticallyCancelling shouldAutomaticallyCancel: Bool,
-                                     forResponse onResponse: @escaping (@escaping (DownloadResponse<Value, AFError>) -> Void) -> Void)
+                                     forResponse onResponse: @Sendable @escaping (@escaping (DownloadResponse<Value, AFError>) -> Void) -> Void)
         -> DownloadTask<Value> {
         let task = Task {
             await withTaskCancellationHandler {
@@ -701,4 +702,5 @@ public struct StreamOf<Element>: AsyncSequence {
     }
 }
 
+// swiftformat:options --swiftversion 5.6
 #endif

+ 5 - 0
Source/Request.swift

@@ -972,6 +972,11 @@ extension Request: CustomStringConvertible {
     }
 }
 
+#if swift(>=5.7)
+extension Request: @unchecked Sendable {}
+// extension DataRequest: @unchecked Sendable {}
+#endif
+
 extension Request {
     /// cURL representation of the instance.
     ///

+ 8 - 0
Source/Response.swift

@@ -82,6 +82,10 @@ public struct DataResponse<Success, Failure: Error> {
     }
 }
 
+#if swift(>=5.7)
+extension DataResponse: Sendable where Success: Sendable {}
+#endif
+
 // MARK: -
 
 extension DataResponse: CustomStringConvertible, CustomDebugStringConvertible {
@@ -270,6 +274,10 @@ public struct DownloadResponse<Success, Failure: Error> {
     }
 }
 
+#if swift(>=5.7)
+extension DownloadResponse: Sendable where Success: Sendable {}
+#endif
+
 // MARK: -
 
 extension DownloadResponse: CustomStringConvertible, CustomDebugStringConvertible {