@@ -78,6 +78,69 @@ internal struct CodableVoidClosureWrapper<In: Decodable>: LambdaHandler {
78
78
}
79
79
}
80
80
81
+ // MARK: - Async
82
+
83
+ extension Lambda {
84
+
85
+ /// An async Lambda Closure that takes a `In: Decodable` and returns an `Out: Encodable`
86
+ public typealias CodableAsyncClosure < In: Decodable , Out: Encodable > = ( Lambda . Context , In ) async throws -> Out
87
+
88
+ /// Run a Lambda defined by implementing the `CodableAsyncClosure` function.
89
+ ///
90
+ /// - parameters:
91
+ /// - closure: `CodableAsyncClosure` based Lambda.
92
+ ///
93
+ /// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
94
+ public static func run< In: Decodable , Out: Encodable > ( _ closure: @escaping CodableAsyncClosure < In , Out > ) {
95
+ self . run ( CodableAsyncWrapper ( closure) )
96
+ }
97
+
98
+ /// An asynchronous Lambda Closure that takes a `In: Decodable` and returns nothing.
99
+ public typealias CodableVoidAsyncClosure < In: Decodable > = ( Lambda . Context , In ) async throws -> ( )
100
+
101
+ /// Run a Lambda defined by implementing the `CodableVoidAsyncClosure` function.
102
+ ///
103
+ /// - parameters:
104
+ /// - closure: `CodableVoidAsyncClosure` based Lambda.
105
+ ///
106
+ /// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
107
+ public static func run< In: Decodable > ( _ closure: @escaping CodableVoidAsyncClosure < In > ) {
108
+ self . run ( CodableVoidAsyncWrapper ( closure) )
109
+ }
110
+ }
111
+
112
+ internal struct CodableAsyncWrapper < In: Decodable , Out: Encodable > : AsyncLambdaHandler {
113
+ typealias In = In
114
+ typealias Out = Out
115
+
116
+ private let closure : Lambda . CodableAsyncClosure < In , Out >
117
+
118
+ init ( _ closure: @escaping Lambda . CodableAsyncClosure < In , Out > ) {
119
+ self . closure = closure
120
+ }
121
+
122
+ func handle( context: Lambda . Context , event: In ) async throws -> Out {
123
+ try await self . closure ( context, event)
124
+ }
125
+ }
126
+
127
+ internal struct CodableVoidAsyncWrapper < In: Decodable > : AsyncLambdaHandler {
128
+ typealias In = In
129
+ typealias Out = Void
130
+
131
+ private let closure : Lambda . CodableVoidAsyncClosure < In >
132
+
133
+ init ( _ closure: @escaping Lambda . CodableVoidAsyncClosure < In > ) {
134
+ self . closure = closure
135
+ }
136
+
137
+ func handle( context: Lambda . Context , event: In ) async throws -> Void {
138
+ try await self . closure ( context, event)
139
+ }
140
+ }
141
+
142
+ // MARK: - Codable support
143
+
81
144
/// Implementation of a`ByteBuffer` to `In` decoding
82
145
extension EventLoopLambdaHandler where In: Decodable {
83
146
public func decode( buffer: ByteBuffer ) throws -> In {
0 commit comments