@@ -171,3 +171,70 @@ package struct ClosureHandler<Event: Decodable, Output>: NewLambdaHandler {
171
171
try await self . body ( event, context)
172
172
}
173
173
}
174
+
175
+ extension NewLambdaRuntime {
176
+ /// Initialize an instance with a ``StreamingLambdaHandler`` in the form of a closure.
177
+ /// - Parameter body: The handler in the form of a closure.
178
+ package convenience init (
179
+ body: @Sendable @escaping ( ByteBuffer, LambdaResponseStreamWriter, NewLambdaContext) async throws -> Void
180
+ ) where Handler == StreamingClosureHandler {
181
+ self . init ( handler: StreamingClosureHandler ( body: body) )
182
+ }
183
+
184
+ /// Initialize an instance with a ``NewLambdaHandler`` defined in the form of a closure **with a non-`Void` return type**, an encoder, and a decoder.
185
+ /// - Parameter body: The handler in the form of a closure.
186
+ /// - Parameter encoder: The encoder object that will be used to encode the generic ``Output`` into a ``ByteBuffer``.
187
+ /// - Parameter decoder: The decoder object that will be used to decode the incoming ``ByteBuffer`` event into the generic ``Event`` type.
188
+ package convenience init <
189
+ Event: Decodable ,
190
+ Output: Encodable ,
191
+ Encoder: LambdaOutputEncoder ,
192
+ Decoder: LambdaEventDecoder
193
+ > (
194
+ encoder: Encoder ,
195
+ decoder: Decoder ,
196
+ body: @escaping ( Event , NewLambdaContext ) async throws -> Output
197
+ )
198
+ where
199
+ Handler == LambdaCodableAdapter <
200
+ LambdaHandlerAdapter < Event , Output , ClosureHandler < Event , Output > > ,
201
+ Event ,
202
+ Output ,
203
+ Decoder ,
204
+ Encoder
205
+ >
206
+ {
207
+ let handler = LambdaCodableAdapter (
208
+ encoder: encoder,
209
+ decoder: decoder,
210
+ handler: LambdaHandlerAdapter ( handler: ClosureHandler ( body: body) )
211
+ )
212
+
213
+ self . init ( handler: handler)
214
+ }
215
+
216
+ /// Initialize an instance with a ``NewLambdaHandler`` defined in the form of a closure **with a `Void` return type**, an encoder, and a decoder.
217
+ /// - Parameter body: The handler in the form of a closure.
218
+ /// - Parameter encoder: The encoder object that will be used to encode the generic ``Output`` into a ``ByteBuffer``.
219
+ /// - Parameter decoder: The decoder object that will be used to decode the incoming ``ByteBuffer`` event into the generic ``Event`` type.
220
+ package convenience init < Event: Decodable , Decoder: LambdaEventDecoder > (
221
+ decoder: Decoder ,
222
+ body: @escaping ( Event , NewLambdaContext ) async throws -> Void
223
+ )
224
+ where
225
+ Handler == LambdaCodableAdapter <
226
+ LambdaHandlerAdapter < Event , Void , ClosureHandler < Event , Void > > ,
227
+ Event ,
228
+ Void ,
229
+ Decoder ,
230
+ VoidEncoder
231
+ >
232
+ {
233
+ let handler = LambdaCodableAdapter (
234
+ decoder: decoder,
235
+ handler: LambdaHandlerAdapter ( handler: ClosureHandler ( body: body) )
236
+ )
237
+
238
+ self . init ( handler: handler)
239
+ }
240
+ }
0 commit comments