Improve MVMCoreActionUtility.perform signature. Remove odd default. Use TimeInterval for better typing and to allow split seconds.
This commit is contained in:
parent
c5dab7d70d
commit
2a438e68a7
@ -106,7 +106,7 @@
|
|||||||
parametersWorkQueue.async {
|
parametersWorkQueue.async {
|
||||||
if (returnedList[index] != nil) {
|
if (returnedList[index] != nil) {
|
||||||
MVMCoreLoggingHandler.addError(toLog: MVMCoreErrorObject(title: nil, message: "Client parameter \(parameterType) has already executed. The completion handler should only be called once!", code: ErrorCode.default.rawValue, domain: ErrorDomainNative, location: String(describing: ClientParameterHandler.self))!)
|
MVMCoreLoggingHandler.addError(toLog: MVMCoreErrorObject(title: nil, message: "Client parameter \(parameterType) has already executed. The completion handler should only be called once!", code: ErrorCode.default.rawValue, domain: ErrorDomainNative, location: String(describing: ClientParameterHandler.self))!)
|
||||||
} else {
|
} else {
|
||||||
MVMCoreLoggingHandler.shared()?.logCoreEvent(.clientParameterFetchComplete(name: parameterType, uuid: requestUUID[index], actionId: actionId))
|
MVMCoreLoggingHandler.shared()?.logCoreEvent(.clientParameterFetchComplete(name: parameterType, uuid: requestUUID[index], actionId: actionId))
|
||||||
returnedList[index] = receivedParameter
|
returnedList[index] = receivedParameter
|
||||||
group.leave() // Leaving is only done after setup (barriered).
|
group.leave() // Leaving is only done after setup (barriered).
|
||||||
|
|||||||
@ -15,7 +15,7 @@ public protocol ClientParameterProtocol: ModelHandlerProtocol {
|
|||||||
|
|
||||||
var clientParameterModel: ClientParameterModelProtocol { get set }
|
var clientParameterModel: ClientParameterModelProtocol { get set }
|
||||||
|
|
||||||
func fetchClientParameters(requestParameters: [String: Any], timingOutIn timeout: Double, completionHandler:@escaping ([String: AnyHashable]?) -> ())
|
func fetchClientParameters(requestParameters: [String: Any], timingOutIn timeout: TimeInterval, completionHandler:@escaping ([String: AnyHashable]?) -> ())
|
||||||
|
|
||||||
/// Default parameter for timeout 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 valueOnTimeout() -> [String: AnyHashable]
|
func valueOnTimeout() -> [String: AnyHashable]
|
||||||
@ -28,10 +28,8 @@ public extension ClientParameterProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The handler should call this method to pass the parameter back to the caller.
|
/// The handler should call this method to pass the parameter back to the caller.
|
||||||
func returnParameters(_ isFlatMap: Bool, _ parameter: [String: AnyHashable]?, completionHandler: @escaping ([String: AnyHashable]?) -> ()) {
|
/// If using isFlatMap, you must provide at least 1 element in parameters or it will result in triggering a timeout.
|
||||||
guard let parameter = parameter else {
|
func returnParameters(_ isFlatMap: Bool, _ parameter: [String: AnyHashable], completionHandler: @escaping ([String: AnyHashable]?) -> ()) {
|
||||||
return completionHandler(nil)
|
|
||||||
}
|
|
||||||
if isFlatMap {
|
if isFlatMap {
|
||||||
completionHandler(parameter)
|
completionHandler(parameter)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -27,7 +27,7 @@ public extension MVMCoreActionUtility {
|
|||||||
- Parameter timemout: the time the operation has to finish before throwing a timeout error.
|
- Parameter timemout: the time the operation has to finish before throwing a timeout error.
|
||||||
- Parameter operation: the operation to perform.
|
- Parameter operation: the operation to perform.
|
||||||
*/
|
*/
|
||||||
static func perform<T>(with timeout: Int = 1, operation: @escaping @Sendable () async throws -> T) async throws -> T {
|
static func perform<T>(withTimeout timeout: TimeInterval, operation: @escaping @Sendable () async throws -> T) async throws -> T {
|
||||||
return try await withCheckedThrowingContinuation { continuation in
|
return try await withCheckedThrowingContinuation { continuation in
|
||||||
Task {
|
Task {
|
||||||
await withThrowingTaskGroup(of: T.self) { group in
|
await withThrowingTaskGroup(of: T.self) { group in
|
||||||
@ -40,7 +40,7 @@ public extension MVMCoreActionUtility {
|
|||||||
// Task for time out.
|
// Task for time out.
|
||||||
group.addTask {
|
group.addTask {
|
||||||
try Task.checkCancellation()
|
try Task.checkCancellation()
|
||||||
try await Task.sleep(nanoseconds: UInt64(timeout) * NSEC_PER_SEC)
|
try await Task.sleep(nanoseconds: UInt64(timeout * TimeInterval(NSEC_PER_SEC)))
|
||||||
throw MVMCoreActionUtilityError.timeOut
|
throw MVMCoreActionUtilityError.timeOut
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user