@@ -85,9 +85,18 @@ extension LambdaHandler {
85
85
86
86
// MARK: - AsyncLambdaHandler
87
87
88
- #if compiler(>=5.5) && $AsyncAwait
88
+ #if compiler(>=5.5)
89
89
/// Strongly typed, processing protocol for a Lambda that takes a user defined `In` and returns a user defined `Out` async.
90
+ @available ( macOS 9999 , iOS 9999 , watchOS 9999 , tvOS 9999 , * )
90
91
public protocol AsyncLambdaHandler : EventLoopLambdaHandler {
92
+ /// The Lambda initialization method
93
+ /// Use this method to initialize resources that will be used in every request.
94
+ ///
95
+ /// Examples for this can be HTTP or database clients.
96
+ /// - parameters:
97
+ /// - context: Runtime `InitializationContext`.
98
+ init ( context: Lambda . InitializationContext ) async throws
99
+
91
100
/// The Lambda handling method
92
101
/// Concrete Lambda handlers implement this method to provide the Lambda functionality.
93
102
///
@@ -99,6 +108,7 @@ public protocol AsyncLambdaHandler: EventLoopLambdaHandler {
99
108
func handle( event: In , context: Lambda . Context ) async throws -> Out
100
109
}
101
110
111
+ @available ( macOS 9999 , iOS 9999 , watchOS 9999 , tvOS 9999 , * )
102
112
extension AsyncLambdaHandler {
103
113
public func handle( context: Lambda . Context , event: In ) -> EventLoopFuture < Out > {
104
114
let promise = context. eventLoop. makePromise ( of: Out . self)
@@ -108,6 +118,13 @@ extension AsyncLambdaHandler {
108
118
return promise. futureResult
109
119
}
110
120
}
121
+
122
+ @available ( macOS 9999 , iOS 9999 , watchOS 9999 , tvOS 9999 , * )
123
+ extension AsyncLambdaHandler {
124
+ public static func main( ) {
125
+ Lambda . run ( Self . init)
126
+ }
127
+ }
111
128
#endif
112
129
113
130
// MARK: - EventLoopLambdaHandler
0 commit comments