@@ -19,7 +19,7 @@ import NIOCore
19
19
/// `LambdaRuntime` manages the Lambda process lifecycle.
20
20
///
21
21
/// Use this API, if you build a higher level web framework which shall be able to run inside the Lambda environment.
22
- public final class LambdaRuntime < Handler: ByteBufferLambdaHandler > {
22
+ public final class LambdaRuntime < Handler: CoreByteBufferLambdaHandler > {
23
23
private let eventLoop : EventLoop
24
24
private let shutdownPromise : EventLoopPromise < Int >
25
25
private let logger : Logger
@@ -34,23 +34,14 @@ public final class LambdaRuntime<Handler: ByteBufferLambdaHandler> {
34
34
}
35
35
}
36
36
37
- /// Create a new `LambdaRuntime`.
38
- ///
39
- /// - parameters:
40
- /// - handlerType: The ``ByteBufferLambdaHandler`` type the `LambdaRuntime` shall create and manage.
41
- /// - eventLoop: An `EventLoop` to run the Lambda on.
42
- /// - logger: A `Logger` to log the Lambda events.
43
- public convenience init ( _ handlerType: Handler . Type , eventLoop: EventLoop , logger: Logger ) {
44
- self . init ( handlerProvider: handlerType. makeHandler ( context: ) , eventLoop: eventLoop, logger: logger, configuration: . init( ) )
45
- }
46
-
47
37
/// Create a new `LambdaRuntime`.
48
38
///
49
39
/// - parameters:
50
40
/// - handlerProvider: A provider of the ``ByteBufferLambdaHandler`` the `LambdaRuntime` will manage.
51
41
/// - eventLoop: An `EventLoop` to run the Lambda on.
52
42
/// - logger: A `Logger` to log the Lambda events.
53
- public convenience init (
43
+ @usableFromInline
44
+ convenience init (
54
45
handlerProvider: @escaping ( LambdaInitializationContext ) -> EventLoopFuture < Handler > ,
55
46
eventLoop: EventLoop ,
56
47
logger: Logger
@@ -63,6 +54,12 @@ public final class LambdaRuntime<Handler: ByteBufferLambdaHandler> {
63
54
)
64
55
}
65
56
57
+ /// Create a new `LambdaRuntime`.
58
+ ///
59
+ /// - parameters:
60
+ /// - handlerProvider: A provider of the ``ByteBufferLambdaHandler`` the `LambdaRuntime` will manage.
61
+ /// - eventLoop: An `EventLoop` to run the Lambda on.
62
+ /// - logger: A `Logger` to log the Lambda events.
66
63
init (
67
64
handlerProvider: @escaping ( LambdaInitializationContext ) -> EventLoopFuture < Handler > ,
68
65
eventLoop: EventLoop ,
@@ -203,7 +200,7 @@ public final class LambdaRuntime<Handler: ByteBufferLambdaHandler> {
203
200
private enum State {
204
201
case idle
205
202
case initializing
206
- case active( LambdaRunner , any ByteBufferLambdaHandler )
203
+ case active( LambdaRunner , any CoreByteBufferLambdaHandler )
207
204
case shuttingdown
208
205
case shutdown
209
206
@@ -232,8 +229,16 @@ public enum LambdaRuntimeFactory {
232
229
/// - eventLoop: An `EventLoop` to run the Lambda on.
233
230
/// - logger: A `Logger` to log the Lambda events.
234
231
@inlinable
235
- public static func makeRuntime< H: SimpleLambdaHandler > ( _ handlerType: H . Type , eventLoop: any EventLoop , logger: Logger ) -> LambdaRuntime < some ByteBufferLambdaHandler > {
236
- LambdaRuntime < CodableSimpleLambdaHandler < H > > ( CodableSimpleLambdaHandler< H> . self , eventLoop: eventLoop, logger: logger)
232
+ public static func makeRuntime< Handler: SimpleLambdaHandler > (
233
+ _ handlerType: Handler . Type ,
234
+ eventLoop: any EventLoop ,
235
+ logger: Logger
236
+ ) -> LambdaRuntime < some ByteBufferLambdaHandler > {
237
+ LambdaRuntime< CodableSimpleLambdaHandler< Handler>>(
238
+ handlerProvider: CodableSimpleLambdaHandler< Handler> . makeHandler( context: ) ,
239
+ eventLoop: eventLoop,
240
+ logger: logger
241
+ )
237
242
}
238
243
239
244
/// Create a new `LambdaRuntime`.
@@ -243,8 +248,16 @@ public enum LambdaRuntimeFactory {
243
248
/// - eventLoop: An `EventLoop` to run the Lambda on.
244
249
/// - logger: A `Logger` to log the Lambda events.
245
250
@inlinable
246
- public static func makeRuntime< H: LambdaHandler > ( _ handlerType: H . Type , eventLoop: any EventLoop , logger: Logger ) -> LambdaRuntime < some ByteBufferLambdaHandler > {
247
- LambdaRuntime < CodableLambdaHandler < H > > ( CodableLambdaHandler< H> . self , eventLoop: eventLoop, logger: logger)
251
+ public static func makeRuntime< Handler: LambdaHandler > (
252
+ _ handlerType: Handler . Type ,
253
+ eventLoop: any EventLoop ,
254
+ logger: Logger
255
+ ) -> LambdaRuntime < some CoreByteBufferLambdaHandler > {
256
+ LambdaRuntime< CodableLambdaHandler< Handler>>(
257
+ handlerProvider: CodableLambdaHandler< Handler> . makeHandler( context: ) ,
258
+ eventLoop: eventLoop,
259
+ logger: logger
260
+ )
248
261
}
249
262
250
263
/// Create a new `LambdaRuntime`.
@@ -254,28 +267,13 @@ public enum LambdaRuntimeFactory {
254
267
/// - eventLoop: An `EventLoop` to run the Lambda on.
255
268
/// - logger: A `Logger` to log the Lambda events.
256
269
@inlinable
257
- public static func makeRuntime< H: EventLoopLambdaHandler > ( _ handlerType: H . Type , eventLoop: any EventLoop , logger: Logger ) -> LambdaRuntime < some ByteBufferLambdaHandler > {
258
- LambdaRuntime < CodableEventLoopLambdaHandler < H > > ( CodableEventLoopLambdaHandler< H> . self , eventLoop: eventLoop, logger: logger)
259
- }
260
-
261
- /// Create a new `LambdaRuntime`.
262
- ///
263
- /// - parameters:
264
- /// - handlerProvider: A provider of the ``SimpleLambdaHandler`` the `LambdaRuntime` will manage.
265
- /// - eventLoop: An `EventLoop` to run the Lambda on.
266
- /// - logger: A `Logger` to log the Lambda events.
267
- @inlinable
268
- public static func makeRuntime< H: SimpleLambdaHandler > (
269
- handlerProvider: @escaping ( LambdaInitializationContext ) -> EventLoopFuture < H > ,
270
+ public static func makeRuntime< Handler: EventLoopLambdaHandler > (
271
+ _ handlerType: Handler . Type ,
270
272
eventLoop: any EventLoop ,
271
273
logger: Logger
272
- ) -> LambdaRuntime < some ByteBufferLambdaHandler > {
273
- LambdaRuntime (
274
- handlerProvider: { context in
275
- handlerProvider ( context) . map {
276
- CodableSimpleLambdaHandler ( handler: $0, allocator: context. allocator)
277
- }
278
- } ,
274
+ ) -> LambdaRuntime < some CoreByteBufferLambdaHandler > {
275
+ LambdaRuntime< CodableEventLoopLambdaHandler< Handler>>(
276
+ handlerProvider: CodableEventLoopLambdaHandler< Handler> . makeHandler( context: ) ,
279
277
eventLoop: eventLoop,
280
278
logger: logger
281
279
)
@@ -284,21 +282,17 @@ public enum LambdaRuntimeFactory {
284
282
/// Create a new `LambdaRuntime`.
285
283
///
286
284
/// - parameters:
287
- /// - handlerProvider: A provider of the ``LambdaHandler `` the `LambdaRuntime` will manage.
285
+ /// - handlerType: The ``EventLoopLambdaHandler `` type the `LambdaRuntime` shall create and manage.
288
286
/// - eventLoop: An `EventLoop` to run the Lambda on.
289
287
/// - logger: A `Logger` to log the Lambda events.
290
288
@inlinable
291
- public static func makeRuntime< H : LambdaHandler > (
292
- handlerProvider : @escaping ( LambdaInitializationContext ) -> EventLoopFuture < H > ,
289
+ public static func makeRuntime< Handler : ByteBufferLambdaHandler > (
290
+ _ handlerType : Handler . Type ,
293
291
eventLoop: any EventLoop ,
294
292
logger: Logger
295
- ) -> LambdaRuntime < some ByteBufferLambdaHandler > {
296
- LambdaRuntime (
297
- handlerProvider: { context in
298
- handlerProvider ( context) . map {
299
- CodableLambdaHandler ( handler: $0, allocator: context. allocator)
300
- }
301
- } ,
293
+ ) -> LambdaRuntime < some CoreByteBufferLambdaHandler > {
294
+ LambdaRuntime < Handler > (
295
+ handlerProvider: Handler . makeHandler ( context: ) ,
302
296
eventLoop: eventLoop,
303
297
logger: logger
304
298
)
@@ -311,17 +305,13 @@ public enum LambdaRuntimeFactory {
311
305
/// - eventLoop: An `EventLoop` to run the Lambda on.
312
306
/// - logger: A `Logger` to log the Lambda events.
313
307
@inlinable
314
- public static func makeRuntime< H : EventLoopLambdaHandler > (
315
- handlerProvider: @escaping ( LambdaInitializationContext ) -> EventLoopFuture < H > ,
308
+ public static func makeRuntime< Handler : CoreByteBufferLambdaHandler > (
309
+ handlerProvider: @escaping ( LambdaInitializationContext ) -> EventLoopFuture < Handler > ,
316
310
eventLoop: any EventLoop ,
317
311
logger: Logger
318
- ) -> LambdaRuntime < some ByteBufferLambdaHandler > {
312
+ ) -> LambdaRuntime < Handler > {
319
313
LambdaRuntime (
320
- handlerProvider: { context in
321
- handlerProvider ( context) . map {
322
- CodableEventLoopLambdaHandler ( handler: $0, allocator: context. allocator)
323
- }
324
- } ,
314
+ handlerProvider: handlerProvider,
325
315
eventLoop: eventLoop,
326
316
logger: logger
327
317
)
0 commit comments