Explorar o código

Refactor Lock Usage and Introduce Protector (#2290)

* Drop iOS 8 / macOS 10.10 support and remove all workarounds.

* First draft of response serializer refactor and decodable serializers.

* Refactor serializer protocols and implementations.

* Finish refactors, update inline docs.

* Remove download serializer from Data, as it’s default now.

* Update whitespace.

* Add failure expectation test.

* Initial versions of Mutex and Protector.

* Rename value to unsafeValue.

* Add UnfairLock.

* Use UnfairLock on supported OSes, hide everything.

* Clean whitespace.

* Cleanup based on comments.

* Remove TODO.
Jon Shier %!s(int64=8) %!d(string=hai) anos
pai
achega
01dfde0468

+ 4 - 3
Source/Mutex+Protector.swift

@@ -24,7 +24,6 @@
 
 import Foundation
 
-
 /// A lock abstraction.
 private protocol Lock {
     func lock()
@@ -77,8 +76,9 @@ final class Mutex: Lock {
         let result = pthread_mutex_unlock(&mutex)
         assert(result == 0, "Failed to unlock mutex")
     }
+}
 
-    /// Execute a value producing closure while aquiring the mutex.
+// MARK: -
     ///
     /// - Parameter closure: The closure to run.
     /// - Returns:           The value the closure generated.
@@ -109,9 +109,10 @@ final class UnfairLock: Lock {
 
     fileprivate func unlock() {
         os_unfair_lock_unlock(&unfairLock)
+}
     }
 
-    /// Execute a value producing closure while aquiring the lock.
+// MARK: -
     ///
     /// - Parameter closure: The closure to run.
     /// - Returns:           The value the closure generated.

+ 3 - 3
Source/ResponseSerialization.swift

@@ -56,14 +56,14 @@ public extension DownloadResponseSerializerProtocol where Self: DataResponseSeri
         guard let fileURL = fileURL else {
             throw AFError.responseSerializationFailed(reason: .inputFileNil)
         }
-        
+
         let data: Data
         do {
             data = try Data(contentsOf: fileURL)
         } catch {
             throw AFError.responseSerializationFailed(reason: .inputFileReadFailed(at: fileURL))
         }
-        
+
         do {
             return try serialize(request: request, response: response, data: data, error: error)
         } catch {
@@ -392,7 +392,7 @@ public final class StringResponseSerializer: ResponseSerializer {
         }
 
         let actualEncoding = convertedEncoding ?? .isoLatin1
-        
+
         guard let string = String(data: validData, encoding: actualEncoding) else {
             throw AFError.responseSerializationFailed(reason: .stringSerializationFailed(encoding: actualEncoding))
         }

+ 1 - 1
Tests/ResponseSerializationTests.swift

@@ -433,7 +433,7 @@ class DataResponseSerializationTestCase: BaseTestCase {
     }
 
     // MARK: JSONDecodableResponseSerializer
-    
+
     struct DecodableValue: Codable {
         let string: String
     }