@@ -25,18 +25,14 @@ import NIO
25
25
public enum Lambda {
26
26
public typealias Handler = ByteBufferLambdaHandler
27
27
28
- /// `ByteBufferLambdaHandler` factory.
29
- ///
30
- /// A function that takes a `InitializationContext` and returns an `EventLoopFuture` of a `ByteBufferLambdaHandler`
31
- public typealias HandlerFactory = ( InitializationContext ) -> EventLoopFuture < Handler >
32
-
33
28
/// Run a Lambda defined by implementing the `LambdaHandler` protocol.
34
29
///
35
30
/// - parameters:
36
31
/// - handler: `ByteBufferLambdaHandler` based Lambda.
37
32
///
38
33
/// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
39
- public static func run( _ handler: Handler ) {
34
+ @inlinable
35
+ public static func run< H: Handler > ( _ handler: H ) {
40
36
if case . failure( let error) = self . run ( handler: handler) {
41
37
fatalError ( " \( error) " )
42
38
}
@@ -50,7 +46,8 @@ public enum Lambda {
50
46
/// - factory: A `ByteBufferLambdaHandler` factory.
51
47
///
52
48
/// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
53
- public static func run( _ factory: @escaping HandlerFactory ) {
49
+ @inlinable
50
+ public static func run< H: Handler > ( _ factory: @escaping ( InitializationContext ) -> EventLoopFuture < H > ) {
54
51
if case . failure( let error) = self . run ( factory: factory) {
55
52
fatalError ( " \( error) " )
56
53
}
@@ -62,7 +59,8 @@ public enum Lambda {
62
59
/// - factory: A `ByteBufferLambdaHandler` factory.
63
60
///
64
61
/// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
65
- public static func run( _ factory: @escaping ( InitializationContext ) throws -> Handler ) {
62
+ @inlinable
63
+ public static func run< H: Handler > ( _ factory: @escaping ( InitializationContext ) throws -> H ) {
66
64
if case . failure( let error) = self . run ( factory: factory) {
67
65
fatalError ( " \( error) " )
68
66
}
@@ -77,14 +75,16 @@ public enum Lambda {
77
75
}
78
76
79
77
// for testing and internal use
80
- internal static func run( configuration: Configuration = . init( ) , handler: Handler ) -> Result < Int , Error > {
78
+ @inlinable
79
+ internal static func run< H: Handler > ( configuration: Configuration = . init( ) , handler: H ) -> Result < Int , Error > {
81
80
self . run ( configuration: configuration, factory: { $0. eventLoop. makeSucceededFuture ( handler) } )
82
81
}
83
82
84
83
// for testing and internal use
85
- internal static func run( configuration: Configuration = . init( ) , factory: @escaping ( InitializationContext ) throws -> Handler ) -> Result < Int , Error > {
86
- self . run ( configuration: configuration, factory: { context -> EventLoopFuture < Handler > in
87
- let promise = context. eventLoop. makePromise ( of: Handler . self)
84
+ @inlinable
85
+ internal static func run< H: Handler > ( configuration: Configuration = . init( ) , factory: @escaping ( InitializationContext ) throws -> H ) -> Result < Int , Error > {
86
+ self . run ( configuration: configuration, factory: { context -> EventLoopFuture < H > in
87
+ let promise = context. eventLoop. makePromise ( of: H . self)
88
88
// if we have a callback based handler factory, we offload the creation of the handler
89
89
// onto the default offload queue, to ensure that the eventloop is never blocked.
90
90
Lambda . defaultOffloadQueue. async {
@@ -99,8 +99,9 @@ public enum Lambda {
99
99
}
100
100
101
101
// for testing and internal use
102
- internal static func run( configuration: Configuration = . init( ) , factory: @escaping HandlerFactory ) -> Result < Int , Error > {
103
- let _run = { ( configuration: Configuration , factory: @escaping HandlerFactory ) -> Result < Int , Error > in
102
+ @inlinable
103
+ static func run< H: Handler > ( configuration: Configuration = . init( ) , factory: @escaping ( InitializationContext ) -> EventLoopFuture < H > ) -> Result < Int , Error > {
104
+ let _run = { ( configuration: Configuration , factory: @escaping ( InitializationContext ) -> EventLoopFuture < H > ) -> Result < Int , Error > in
104
105
Backtrace . install ( )
105
106
var logger = Logger ( label: " Lambda " )
106
107
logger. logLevel = configuration. general. logLevel
0 commit comments