review
This commit is contained in:
parent
931d10f45a
commit
c369958f5e
@ -10,15 +10,10 @@ import Foundation
|
||||
|
||||
public protocol ClientParameterModelProtocol: ModelProtocol {
|
||||
var type: String { get }
|
||||
var isFlatMap: Bool? { get }
|
||||
}
|
||||
|
||||
public extension ClientParameterModelProtocol {
|
||||
|
||||
var isFlatMap: Bool? {
|
||||
return false
|
||||
}
|
||||
|
||||
var type: String {
|
||||
get { Self.identifier }
|
||||
}
|
||||
|
||||
@ -15,15 +15,15 @@ public protocol ClientParameterProtocol {
|
||||
init(_ clientParameterModel:ClientParameterModelProtocol)
|
||||
|
||||
var isFlatMap: Bool { get }
|
||||
var clientParameterModel:ClientParameterModelProtocol? { get set}
|
||||
var clientParameterModel: ClientParameterModelProtocol? { get set }
|
||||
|
||||
func defaultErrorString() -> String
|
||||
func fetchClientParameters(requestParameters: [String: Any], timingOutIn timeout: Double, completionHandler:@escaping (AnyHashable?) -> ())
|
||||
|
||||
/// The handler should call this methos to pass the paramter back to the caller.
|
||||
/// The handler should call this method to pass the parameter back to the caller.
|
||||
func returnParameters(_ paramter: [String: AnyHashable]?, completionHandler: @escaping (AnyHashable?) -> ())
|
||||
|
||||
/// Default parameter for timout scenarios. It will use the protocol extension method bydefault. Can override to send custom values.
|
||||
/// Default parameter for timeout scenarios. It will use the protocol extension method bydefault. Can override to send custom values.
|
||||
func defaultValue() -> AnyHashable
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ public extension ClientParameterProtocol {
|
||||
return [Self.name: defaultErrorString()]
|
||||
}
|
||||
|
||||
init(_ clientParameterModel:ClientParameterModelProtocol) {
|
||||
init(_ clientParameterModel: ClientParameterModelProtocol) {
|
||||
self.init()
|
||||
self.clientParameterModel = clientParameterModel
|
||||
}
|
||||
|
||||
@ -58,7 +58,6 @@ import Foundation
|
||||
|
||||
let parametersWorkQueue = DispatchQueue(label: "com.mva.clientparameter")
|
||||
let group = DispatchGroup()
|
||||
//let defaultErrorString = "failed_to_collect."
|
||||
|
||||
// Dispatch setup on queue to ensure setup is complete before completion callbacks.
|
||||
parametersWorkQueue.async(group: group, qos: .userInitiated) { [weak self] in
|
||||
@ -76,14 +75,12 @@ import Foundation
|
||||
|
||||
var mergedParametersList: [String: AnyHashable] {
|
||||
var parametersList: [String: AnyHashable] = [:]
|
||||
var index = 0
|
||||
for item in returnedList {
|
||||
for (index, item) in returnedList.enumerated() {
|
||||
if item.count == 0, let defaultValue = parameterHandlerList[index].defaultValue() as? [String: AnyHashable] {
|
||||
parametersList = parametersList.merging(defaultValue) { (_, new) in new }
|
||||
} else {
|
||||
parametersList = parametersList.merging(item) { (_, new) in new }
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
return parametersList
|
||||
}
|
||||
@ -106,10 +103,8 @@ import Foundation
|
||||
parametersWorkQueue.asyncAfter(deadline: .now() + .seconds(Int(timeout)), execute: timeoutWorkItem)
|
||||
|
||||
// Setup the parameter execution.
|
||||
var index = -1
|
||||
for parameterHandler in parameterHandlerList {
|
||||
group.enter()
|
||||
index += 1
|
||||
for (index, parameterHandler) in parameterHandlerList.enumerated() {
|
||||
group.enter()
|
||||
parameterHandler.fetchClientParameters(requestParameters: requestParameters,
|
||||
timingOutIn: timeout) { (receivedParameter) in
|
||||
// Queue the results for merge.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user