concurrent queue and timout
This commit is contained in:
parent
a5960728c4
commit
d49111766b
@ -18,13 +18,14 @@ public extension MVMCoreActionHandler {
|
||||
|
||||
@objc func setClientParameter(with actionMap: [String: Any]?, completionHandler: @escaping ([String : Any]?) -> ()) {
|
||||
|
||||
guard let paramsList = actionMap?.optionalArrayForChainOfKeysOrIndexes(["clientParameters", "list"]) as? [[String : Any]] else {
|
||||
guard let clientParameters = actionMap?.optionalDictionaryForKey("clientParameters") else {
|
||||
completionHandler(actionMap)
|
||||
return
|
||||
}
|
||||
|
||||
MVMCoreLoadingOverlayHandler.sharedLoadingOverlay()?.startLoading()
|
||||
ClientParameterRegistry.injectParams(with: paramsList) { (clientParams) in
|
||||
|
||||
ClientParameterRegistry.injectParams(with: clientParameters) { (clientParams) in
|
||||
guard let clientParams = clientParams else {
|
||||
completionHandler(actionMap)
|
||||
return
|
||||
|
||||
@ -23,25 +23,41 @@ import Foundation
|
||||
return patamType.init()
|
||||
}
|
||||
|
||||
static func injectParams(with paramsModelList: [[String: Any]]?,
|
||||
static func injectParams(with clientParameters: [String: Any]?,
|
||||
completionHandler:@escaping ([String: Any]?) -> ()) {
|
||||
|
||||
let clientParameterRegistry = ClientParameterRegistry.shared
|
||||
guard let paramsModelList = paramsModelList else {
|
||||
guard let clientParameters = clientParameters,
|
||||
let paramsModelList = clientParameters.optionalArrayForKey("list") as? [[String: Any]] else {
|
||||
completionHandler(nil)
|
||||
return
|
||||
}
|
||||
|
||||
var paramsList: [String: Any] = [:]
|
||||
MVMCoreDispatchUtility.performSyncBlock( inBackground: { () -> Void in
|
||||
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
|
||||
let concurrentQueue = DispatchQueue(label: "com.mva.clientparam", attributes: .concurrent)
|
||||
let group = DispatchGroup()
|
||||
for param in paramsModelList {
|
||||
if let clientParam = clientParameterRegistry.injectParam(param) {
|
||||
paramsList.merge(clientParam) { (_, new) in new }
|
||||
group.enter()
|
||||
concurrentQueue.async(flags: .barrier) {
|
||||
if let clientParam = clientParameterRegistry.injectParam(param) {
|
||||
paramsList.merge(clientParam) { (_, new) in new }
|
||||
}
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
})
|
||||
completionHandler(paramsList)
|
||||
print("")
|
||||
|
||||
if let timeout = clientParameters.optionalCGFloatForKey("timeout") {
|
||||
let dispatchAfterTime = DispatchTimeInterval.seconds(Int(timeout))
|
||||
_ = group.wait(timeout: .now() + dispatchAfterTime)
|
||||
} else {
|
||||
group.wait()
|
||||
}
|
||||
|
||||
completionHandler(paramsList)
|
||||
}
|
||||
}
|
||||
|
||||
func injectParam( _ param: [String: Any]) -> [String: Any]? {
|
||||
@ -54,9 +70,7 @@ import Foundation
|
||||
|
||||
|
||||
/// Add all registry here.
|
||||
public static func registerParameters() {
|
||||
|
||||
}
|
||||
public static func registerParameters() { }
|
||||
|
||||
/// Register Default Core Bridge Objects
|
||||
public static func register<T:ClientParameterProtocol, M: ModelProtocol>(parameter: T.Type, type: M.Type) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user