diff --git a/Sources/BraintreeCore/Configuration/ConfigurationCallbackStorage.swift b/Sources/BraintreeCore/Configuration/ConfigurationCallbackStorage.swift index c936b26ef7..a2ccbb430a 100644 --- a/Sources/BraintreeCore/Configuration/ConfigurationCallbackStorage.swift +++ b/Sources/BraintreeCore/Configuration/ConfigurationCallbackStorage.swift @@ -1,7 +1,7 @@ import Foundation -/// Used to store, access, and manage an array of to-be-invoked `BTConfiguration` GET result callbacks in a thread-safe manner -actor ConfigurationCallbackStorage { +/// Used to store, access, and manage an array of to-be-invoked `BTConfiguration` GET result callbacks +class ConfigurationCallbackStorage { private var pendingCompletions: [(BTConfiguration?, Error?) -> Void] = [] diff --git a/Sources/BraintreeCore/Configuration/ConfigurationLoader.swift b/Sources/BraintreeCore/Configuration/ConfigurationLoader.swift index 5c16a124cb..ecc15220f6 100644 --- a/Sources/BraintreeCore/Configuration/ConfigurationLoader.swift +++ b/Sources/BraintreeCore/Configuration/ConfigurationLoader.swift @@ -41,32 +41,30 @@ class ConfigurationLoader { return } - Task { - await pendingCompletions.add(completion) - - // If this is the 1st `v1/config` GET attempt, proceed with firing the network request. - // Otherwise, there is already a pending network request. - if await pendingCompletions.count == 1 { - http.get(configPath, parameters: BTConfigurationRequest()) { [weak self] body, response, error in - guard let self else { - self?.notifyCompletions(nil, BTAPIClientError.deallocated) - return - } + pendingCompletions.add(completion) + + // If this is the 1st `v1/config` GET attempt, proceed with firing the network request. + // Otherwise, there is already a pending network request. + if pendingCompletions.count == 1 { + http.get(configPath, parameters: BTConfigurationRequest()) { [weak self] body, response, error in + guard let self else { + self?.notifyCompletions(nil, BTAPIClientError.deallocated) + return + } + + if let error { + notifyCompletions(nil, error) + return + } else if response?.statusCode != 200 || body == nil { + notifyCompletions(nil, BTAPIClientError.configurationUnavailable) + return + } else { + let configuration = BTConfiguration(json: body) + + try? configurationCache.putInCache(authorization: http.authorization.bearer, configuration: configuration) - if let error { - notifyCompletions(nil, error) - return - } else if response?.statusCode != 200 || body == nil { - notifyCompletions(nil, BTAPIClientError.configurationUnavailable) - return - } else { - let configuration = BTConfiguration(json: body) - - try? configurationCache.putInCache(authorization: http.authorization.bearer, configuration: configuration) - - notifyCompletions(configuration, nil) - return - } + notifyCompletions(configuration, nil) + return } } } @@ -87,6 +85,6 @@ class ConfigurationLoader { // MARK: - Private Methods func notifyCompletions(_ configuration: BTConfiguration?, _ error: Error?) { - Task { await pendingCompletions.invoke(configuration, error) } + pendingCompletions.invoke(configuration, error) } }