Browse Source

Treat async context cancellation as task cancellation

onevcat 1 month ago
parent
commit
0f07a9dfe6

+ 4 - 1
Sources/General/KingfisherError.swift

@@ -368,11 +368,14 @@ public enum KingfisherError: Error {
 
     // MARK: Helper Properties & Methods
 
-    /// A helper property to determine if this error is of type `RequestErrorReason.taskCancelled`.
+    /// A helper property to determine if this error is a cancellation error.
     public var isTaskCancelled: Bool {
         if case .requestError(reason: .taskCancelled) = self {
             return true
         }
+        if case .requestError(reason: .asyncTaskContextCancelled) = self {
+            return true
+        }
         return false
     }
 

+ 7 - 1
Tests/KingfisherTests/KingfisherManagerTests.swift

@@ -306,7 +306,13 @@ class KingfisherManagerTests: XCTestCase {
                 XCTFail("Task should have been cancelled")
             } catch {
                 // Should be cancelled
-                XCTAssertTrue((error as? KingfisherError)?.isTaskCancelled == true)
+                if let kfError = error as? KingfisherError {
+                    XCTAssertTrue(kfError.isTaskCancelled)
+                } else if error is CancellationError {
+                    XCTAssertTrue(true)
+                } else {
+                    XCTFail("Unexpected error: \(error)")
+                }
             }
         }