@@ -58,13 +58,29 @@ extension LambdaHandler {
58
58
59
59
public func handle( _ event: Event , context: LambdaContext ) -> EventLoopFuture < Output > {
60
60
let promise = context. eventLoop. makePromise ( of: Output . self)
61
+ // using an unchecked sendable wrapper for the handler
62
+ // this is safe since lambda runtime is designed to calls the handler serially
63
+ let handler = UncheckedSendableHandler ( underlying: self )
61
64
promise. completeWithTask {
62
- try await self . handle ( event, context: context)
65
+ try await handler . handle ( event, context: context)
63
66
}
64
67
return promise. futureResult
65
68
}
66
69
}
67
70
71
+ /// unchecked sendable wrapper for the handler
72
+ @available ( macOS 12 , iOS 15 , tvOS 15 , watchOS 8 , * )
73
+ fileprivate struct UncheckedSendableHandler < Underlying: LambdaHandler > : @unchecked Sendable {
74
+ let underlying : Underlying
75
+
76
+ init ( underlying: Underlying ) {
77
+ self . underlying = underlying
78
+ }
79
+
80
+ func handle( _ event: Underlying . Event , context: LambdaContext ) async throws -> Underlying . Output {
81
+ try await self . underlying. handle ( event, context: context)
82
+ }
83
+ }
68
84
#endif
69
85
70
86
// MARK: - EventLoopLambdaHandler
@@ -157,7 +173,7 @@ extension EventLoopLambdaHandler where Output == Void {
157
173
/// - note: This is a low level protocol designed to power the higher level ``EventLoopLambdaHandler`` and
158
174
/// ``LambdaHandler`` based APIs.
159
175
/// Most users are not expected to use this protocol.
160
- public protocol ByteBufferLambdaHandler : _ByteBufferLambdaHandlerSendable {
176
+ public protocol ByteBufferLambdaHandler {
161
177
/// Create your Lambda handler for the runtime.
162
178
///
163
179
/// Use this to initialize all your resources that you want to cache between invocations. This could be database
0 commit comments