Selaa lähdekoodia

Mark necessary types as Sendable

onevcat 1 vuosi sitten
vanhempi
commit
e2ca7fb8b6
2 muutettua tiedostoa jossa 10 lisäystä ja 3 poistoa
  1. 1 1
      Sources/Cache/MemoryStorage.swift
  2. 9 2
      Sources/Networking/ImageDownloader.swift

+ 1 - 1
Sources/Cache/MemoryStorage.swift

@@ -51,7 +51,7 @@ public enum MemoryStorage {
     /// The `MemoryStorage` also includes a scheduled self-cleaning task to evict expired items from memory.
     ///
     /// > This class is thready safe.
-    public class Backend<T: CacheCostCalculable> {
+    public class Backend<T: CacheCostCalculable>: @unchecked Sendable {
         
         let storage = NSCache<NSString, StorageObject<T>>()
 

+ 9 - 2
Sources/Networking/ImageDownloader.swift

@@ -133,22 +133,29 @@ extension DownloadTask {
 }
 
 /// Represents a download manager for requesting an image with a URL from the server.
-open class ImageDownloader {
+open class ImageDownloader: @unchecked Sendable {
 
     // MARK: Singleton
     
     /// The default downloader.
     public static let `default` = ImageDownloader(name: "default")
 
+    private let propertyQueue = DispatchQueue(label: "com.onevcat.Kingfisher.ImageDownloaderPropertyQueue")
+    
     // MARK: Public Properties
     
+    private var _downloadTimeout: TimeInterval = 15.0
+    
     /// The duration before the download times out.
     ///
     /// If the download does not complete before this duration, the URL session will raise a timeout error, which 
     /// Kingfisher wraps and forwards as a ``KingfisherError/ResponseErrorReason/URLSessionError(error:)``.
     ///
     /// The default timeout is set to 15 seconds.
-    open var downloadTimeout: TimeInterval = 15.0
+    open var downloadTimeout: TimeInterval {
+        get { propertyQueue.sync { _downloadTimeout } }
+        set { propertyQueue.sync { _downloadTimeout = newValue } }
+    }
     
     /// A set of trusted hosts when receiving server trust challenges.
     ///