Просмотр исходного кода

Mark ImageProgressive sendable

onevcat 1 год назад
Родитель
Сommit
a00caea378
2 измененных файлов с 15 добавлено и 4 удалено
  1. 1 1
      Sources/Image/ImageProgressive.swift
  2. 14 3
      Sources/Utility/Delegate.swift

+ 1 - 1
Sources/Image/ImageProgressive.swift

@@ -36,7 +36,7 @@ private let sharedProcessingQueue: CallbackQueue =
     .dispatch(DispatchQueue(label: "com.onevcat.Kingfisher.ImageDownloader.Process"))
 
 /// Represents a progressive loading for images which supports this feature.
-public struct ImageProgressive {
+public struct ImageProgressive: Sendable {
     
     /// The updating strategy when an intermediate progressive image is generated and about to be set to the hosting view.
     public enum UpdatingStrategy {

+ 14 - 3
Sources/Utility/Delegate.swift

@@ -68,11 +68,22 @@ import Foundation
 ///     }
 /// }
 ///
-public class Delegate<Input, Output> {
+public class Delegate<Input, Output>: @unchecked Sendable {
     public init() {}
 
-    private var block: ((Input) -> Output?)?
-    private var asyncBlock: ((Input) async -> Output?)?
+    private let propertyQueue = DispatchQueue(label: "com.onevcat.Kingfisher.DelegateQueue")
+    
+    private var _block: ((Input) -> Output?)?
+    private var block: ((Input) -> Output?)? {
+        get { propertyQueue.sync { _block } }
+        set { propertyQueue.sync { _block = newValue } }
+    }
+    
+    private var _asyncBlock: ((Input) async -> Output?)?
+    private var asyncBlock: ((Input) async -> Output?)? {
+        get { propertyQueue.sync { _asyncBlock } }
+        set { propertyQueue.sync { _asyncBlock = newValue } }
+    }
     
     public func delegate<T: AnyObject>(on target: T, block: ((T, Input) -> Output)?) {
         self.block = { [weak target] input in