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