@@ -38,7 +38,7 @@ import Foundation
3838 private var pendingUploads = [ MultipartUpload] ( )
3939 private var uploadResponses = [ NetworkJSONResponse] ( )
4040
41- private var shouldAbort : Bool
41+ private var shouldAbort : Bool = false
4242 private var currentOperation : MultipartUpload ?
4343
4444 private let queue : DispatchQueue
@@ -54,7 +54,6 @@ import Foundation
5454 apiKey: String ,
5555 security: Security ? = nil ) {
5656 self . options = options
57- self . shouldAbort = false
5857 self . queue = queue
5958 self . apiKey = apiKey
6059 self . security = security
@@ -90,18 +89,23 @@ import Foundation
9089 /// - Important: Any already uploaded files **will not** be deleted —
9190 /// only the current file being uploaded (if any) and any pending files will be affected.
9291 ///
93- /// This will trigger `completionHandler`.
92+ /// On success, this will trigger `completionHandler`.
9493 ///
9594 /// - Returns: True on success, false otherwise.
9695 @objc
9796 @discardableResult public func cancel( ) -> Bool {
98- guard currentStatus != . cancelled else { return false }
99-
100- shouldAbort = true
101- currentOperation? . cancel ( )
102- stopUpload ( )
97+ switch currentStatus {
98+ case . notStarted:
99+ fallthrough
100+ case . inProgress:
101+ shouldAbort = true
102+ currentOperation? . cancel ( )
103+ stopUpload ( )
103104
104- return true
105+ return true
106+ default :
107+ return false
108+ }
105109 }
106110
107111 /// Starts upload.
@@ -153,7 +157,7 @@ private extension MultifileUpload {
153157 }
154158
155159 func uploadNextFile( ) {
156- guard shouldAbort == false , let nextUpload = pendingUploads. first else {
160+ guard ! shouldAbort, let nextUpload = pendingUploads. first else {
157161 stopUpload ( )
158162 return
159163 }
0 commit comments