mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
refactor(mobile): cleanup iOS image loading pipeline (#27672)
* refactor: replace DispatchQueue + DispatchSemaphore with OperationQueue for image processing * implement RequestRegistry and UnfairLock for managing cancellable requests * implement requests registry for local and remote image processing * remove Cancellable protocol and cancel method from request registry * refactor: introduce ImageRequest base class with unified cancellation and finish helpers * refactor: add get method to RequestRegistry and streamline request removal in image processing * add guard to cancel to prevent double onCancel calls * fix duplicate code merge issue * refactor(ios): enhance finish method to return callback status * remove unfitting methods form ImageRequest.swift and fix memory issue * revert bad merge * refactor(ios): resolve cancellation issues * refactor(ios): streamline image request completion handling * add return statements * refactor(ios): simplify image request cancellation and registry handling --------- Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
@@ -1,5 +1,32 @@
|
||||
import Foundation
|
||||
|
||||
class ImageRequest: @unchecked Sendable {
|
||||
private struct State: Sendable {
|
||||
var isCancelled = false
|
||||
}
|
||||
|
||||
let completion: @Sendable (Result<[String: Int64]?, any Error>) -> Void
|
||||
private let state: Mutex<State>
|
||||
|
||||
var isCancelled: Bool {
|
||||
get {
|
||||
state.withLock { $0.isCancelled }
|
||||
}
|
||||
set {
|
||||
state.withLock { $0.isCancelled = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
init(completion: @escaping @Sendable (Result<[String: Int64]?, any Error>) -> Void) {
|
||||
self.state = Mutex(State())
|
||||
self.completion = completion
|
||||
}
|
||||
|
||||
func cancel() {
|
||||
isCancelled = true
|
||||
}
|
||||
}
|
||||
|
||||
struct RequestRegistry<T: AnyObject & Sendable>: ~Copyable, Sendable {
|
||||
private let requests = Mutex<[Int64: T]>([:])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user