@@ -19,7 +19,7 @@ import OpenAPIRuntime
19
19
import HTTPTypes
20
20
21
21
/// A Lambda function implemented with a OpenAPI server (implementing `APIProtocol` from Swift OpenAPIRuntime)
22
- public protocol OpenAPILambda : Sendable {
22
+ public protocol OpenAPILambda {
23
23
24
24
associatedtype Event : Decodable
25
25
associatedtype Output : Encodable
@@ -53,7 +53,28 @@ extension OpenAPILambda {
53
53
public static func run( logger: Logger ? = nil ) async throws {
54
54
55
55
let _logger = logger ?? Logger ( label: " OpenAPILambda " )
56
- let lambdaRuntime = try LambdaRuntime ( logger: _logger, body: Self . handler ( ) )
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
57
63
try await lambdaRuntime. run ( )
58
64
}
59
65
}
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 that
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
+ fileprivate struct UnsafeTransferBox < Value> : @unchecked Sendable {
75
+ let value : Value
76
+ init ( value: Value ) {
77
+ self . value = value
78
+ }
79
+ }
80
+ #endif
0 commit comments