File tree 1 file changed +19
-0
lines changed
Sources/AWSLambdaRuntimeCore
1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,25 @@ public enum Lambda {
55
55
fatalError ( " \( error) " )
56
56
}
57
57
}
58
+
59
+ #if compiler(>=5.4) && $AsyncAwait
60
+ public static func run( _ factory: @escaping ( InitializationContext ) async throws -> Handler ) {
61
+ self . run { context -> EventLoopFuture < Handler > in
62
+ @asyncHandler func _createLambda( _ context: InitializationContext , promise: EventLoopPromise < Handler > ) {
63
+ do {
64
+ let handler = try await factory ( context)
65
+ promise. succeed ( handler)
66
+ } catch {
67
+ promise. fail ( error)
68
+ }
69
+ }
70
+
71
+ let promise = context. eventLoop. makePromise ( of: Handler . self)
72
+ _createLambda ( context, promise: promise)
73
+ return promise. futureResult
74
+ }
75
+ }
76
+ #endif
58
77
59
78
/// Run a Lambda defined by implementing the `LambdaHandler` protocol provided via a factory, typically a constructor.
60
79
///
You can’t perform that action at this time.
0 commit comments