@@ -19,10 +19,10 @@ import OpenAPIRuntime
1919import HTTPTypes
2020
2121/// A Lambda function implemented with a OpenAPI server (implementing `APIProtocol` from Swift OpenAPIRuntime)
22- public protocol OpenAPILambda {
22+ public protocol OpenAPILambda : Sendable {
2323
24- associatedtype Event : Decodable
25- associatedtype Output : Encodable
24+ associatedtype Event : Decodable , Sendable
25+ associatedtype Output : Encodable , Sendable
2626
2727 /// Initialize application.
2828 ///
@@ -51,27 +51,8 @@ extension OpenAPILambda {
5151 /// when one is given.
5252 /// - Parameter logger: The logger to use for Lambda runtime logging
5353 public static func run( logger: Logger ? = nil ) async throws {
54-
5554 let _logger = logger ?? Logger ( label: " OpenAPILambda " )
56- #if swift(>=6.2)
57- let box = UnsafeTransferBox ( value: try Self . handler ( ) )
58- let lambdaRuntime = LambdaRuntime ( logger: _logger, body: box. value)
59- #else
60- let lambdaHandler = try Self . handler ( )
61- let lambdaRuntime = LambdaRuntime ( logger: _logger, body: lambdaHandler)
62- #endif
55+ let lambdaRuntime = LambdaRuntime ( logger: _logger, body: try Self . handler ( ) )
6356 try await lambdaRuntime. run ( )
6457 }
6558}
66-
67- // on Swift 6.2, with approachable concurrency, the compiler considers
68- // the `lambdaHandler` can not be sent to the `LambdaRuntime(body:)` directly
69- // despite the fact `lambdaHandler` is not used after the call.
70- // There are two workarounds:
71- // - make `OpenAPILambda` conform to `Sendable`. But this would require users to ensure their implementations are also `Sendable`
72- // - wrap the handler in a `UnsafeTransferBox`
73- #if swift(>=6.2)
74- private struct UnsafeTransferBox < Value> : @unchecked Sendable {
75- let value : Value
76- }
77- #endif
0 commit comments