|
@@ -64,7 +64,11 @@ final class ImageProgressiveProvider: DataReceivingSideEffect {
|
|
|
var onShouldApply: () -> Bool = { return true }
|
|
var onShouldApply: () -> Bool = { return true }
|
|
|
|
|
|
|
|
func onDataReceived(_ session: URLSession, task: SessionDataTask, data: Data) {
|
|
func onDataReceived(_ session: URLSession, task: SessionDataTask, data: Data) {
|
|
|
- update(data: task.mutableData, with: task.callbacks)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
|
+ guard self.onShouldApply() else { return }
|
|
|
|
|
+ self.update(data: task.mutableData, with: task.callbacks)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private let option: ImageProgressive
|
|
private let option: ImageProgressive
|
|
@@ -88,14 +92,9 @@ final class ImageProgressiveProvider: DataReceivingSideEffect {
|
|
|
|
|
|
|
|
func update(data: Data, with callbacks: [SessionDataTask.TaskCallback]) {
|
|
func update(data: Data, with callbacks: [SessionDataTask.TaskCallback]) {
|
|
|
guard !data.isEmpty else { return }
|
|
guard !data.isEmpty else { return }
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
queue.add(minimum: option.scanInterval) { completion in
|
|
queue.add(minimum: option.scanInterval) { completion in
|
|
|
- guard self.onShouldApply() else {
|
|
|
|
|
- self.queue.clean()
|
|
|
|
|
- completion()
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
func decode(_ data: Data) {
|
|
func decode(_ data: Data) {
|
|
|
self.decoder.decode(data, with: callbacks) { image in
|
|
self.decoder.decode(data, with: callbacks) { image in
|
|
|
defer { completion() }
|
|
defer { completion() }
|
|
@@ -104,12 +103,19 @@ final class ImageProgressiveProvider: DataReceivingSideEffect {
|
|
|
self.refresh(image)
|
|
self.refresh(image)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- if self.option.isFastestScan {
|
|
|
|
|
- decode(self.decoder.scanning(data) ?? Data())
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- self.decoder.scanning(data).forEach { decode($0) }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ CallbackQueue.mainCurrentOrAsync.execute {
|
|
|
|
|
+ guard self.onShouldApply() else {
|
|
|
|
|
+ self.queue.clean()
|
|
|
|
|
+ completion()
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if self.option.isFastestScan {
|
|
|
|
|
+ decode(self.decoder.scanning(data) ?? Data())
|
|
|
|
|
+ } else {
|
|
|
|
|
+ self.decoder.scanning(data).forEach { decode($0) }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -250,7 +256,8 @@ private final class ImageProgressiveDecoder {
|
|
|
private final class ImageProgressiveSerialQueue {
|
|
private final class ImageProgressiveSerialQueue {
|
|
|
typealias ClosureCallback = ((@escaping () -> Void)) -> Void
|
|
typealias ClosureCallback = ((@escaping () -> Void)) -> Void
|
|
|
|
|
|
|
|
- private let queue: DispatchQueue = .init(label: "com.onevcat.Kingfisher.ImageProgressive.SerialQueue")
|
|
|
|
|
|
|
+ private let queue: DispatchQueue = //DispatchQueue.main
|
|
|
|
|
+ .init(label: "com.onevcat.Kingfisher.ImageProgressive.SerialQueue")
|
|
|
private var items: [DispatchWorkItem] = []
|
|
private var items: [DispatchWorkItem] = []
|
|
|
private var notify: (() -> Void)?
|
|
private var notify: (() -> Void)?
|
|
|
private var lastTime: TimeInterval?
|
|
private var lastTime: TimeInterval?
|