Andrea-Scuderi opened a new pull request, #153: URL: https://github.com/apache/openwhisk-runtime-swift/pull/153
# Add support for Swift 5.7 - Add new action signatures with async/await and throws - Backward compatibility with old action signatures ### swift57Action - Add support async to Whisk class ### swiftbuild.py - simplify the code added by the build process to: ```swift try await _WhiskRuntime.wiskRunLoop { jsonData in await _WhiskRuntime.runAsyncMain(mainFunction: <action>, json: jsonData) } ``` ### swiftbuild.py.launcher.swift - Add `_WhiskRuntime` struct - Refactor Error messages - Add new signatures ```swift // Examples of Actions supported by Swift 5.7 // Action with Any Input and Any Output func main(args: Any) -> Any { let newArgs = args as! [String:Any] if let name = newArgs["name"] as? String { return [ "greeting" : "Hello \(name)!" ] } else { return [ "greeting" : "Hello stranger!" ] } } // Async Action with Any Input and Any Output func mainAsync(args: Any) async -> Any { do { //async code sleep for 1 sec try await Task.sleep(nanoseconds: 1_000_000_000) let newArgs = args as! [String:Any] if let name = newArgs["name"] as? String { return [ "greeting" : "Hello \(name)!" ] } else { return [ "greeting" : "Hello stranger!" ] } } catch { return ["error" : error.localizedDescription] } } // Async throwing Action with Any Input and Any Output func mainAsyncThrows(args: Any) async throws -> Any { //async code sleep for 1 sec try await Task.sleep(nanoseconds: 1_000_000_000) let newArgs = args as! [String:Any] if let name = newArgs["name"] as? String { return [ "greeting" : "Hello \(name)!" ] } else { return [ "greeting" : "Hello stranger!" ] } } struct Input: Codable { let name: String? } struct Output: Codable { let count: Int } // Action with Codable Input and completion with Codable Output and Error func mainCompletionCodable(input: Input, completion: @escaping (Output?, Error?) -> Void) -> Void { if let name = input.name { let output = Output(count: name.count) completion(output, nil) } else { let output = Output(count: 0) completion(output, nil) } } // Action with Codable Input and completion with Codable Output and Error func mainCompletionCodableNoInput(completion: @escaping (Output?, Error?) -> Void) -> Void { let output = Output(count: 0) completion(output, nil) } // Async throwing Action with Codable Output func mainCodableAsyncThrowsNoInput() async throws -> Output? { try await Task.sleep(nanoseconds: 1_000_000_000) return Output(count: 0) } // Async throwing Action with a Codable Input and a Codable Output func mainCodableAsyncThrows(input: Input) async throws -> Output? { try await Task.sleep(nanoseconds: 1_000_000_000) if let name = input.name { return Output(count: name.count) } else { return Output(count: 0) } } ``` Merry Christmas and Happy New Year! 🎄 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@openwhisk.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org