Skip to content

Commit fe0aa01

Browse files
committed
fix concurrency errors on Swift nightly and swift next
1 parent f4ee52b commit fe0aa01

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

Sources/OpenAPILambda.swift

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import OpenAPIRuntime
1919
import 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
///
@@ -47,22 +47,26 @@ extension OpenAPILambda {
4747
try OpenAPILambdaHandler<Self>().handler
4848
}
4949

50-
/// Run the Lambda handler function for this OpenAPI Lambda implementation with a custom logger, when one is given.
50+
/// Invokes the OpenAPI Lambda handler function for this OpenAPI Lambda implementation
51+
/// - Parameters:
52+
/// - event: The event for the Lambda function
53+
/// - context: The Lambda context
54+
/// - Throws: An error if the handler function fails
55+
/// - Returns: The output of the handler function
56+
private static func handler(event: Event, context: LambdaContext) async throws -> Output {
57+
try await Self.handler()(event, context)
58+
}
59+
60+
/// Start the Lambda Runtime with the Lambda handler function for this OpenAPI Lambda implementation with a custom logger,
61+
/// when one is given.
5162
/// - Parameter logger: The logger to use for Lambda runtime logging
5263
public static func run(logger: Logger? = nil) async throws {
53-
let lambdaRuntime:
54-
LambdaRuntime<
55-
LambdaCodableAdapter<
56-
LambdaHandlerAdapter<Self.Event, Self.Output, ClosureHandler<Self.Event, Self.Output>>, Self.Event,
57-
Self.Output, LambdaJSONEventDecoder, LambdaJSONOutputEncoder<Self.Output>
58-
>
59-
>
60-
if let logger {
61-
lambdaRuntime = try LambdaRuntime(logger: logger, body: Self.handler())
62-
}
63-
else {
64-
lambdaRuntime = try LambdaRuntime(body: Self.handler())
64+
65+
let lambdaRuntime = LambdaRuntime { (event: Event, context: LambdaContext) in
66+
try await Self.handler(event: event, context: context)
6567
}
68+
69+
// let lambdaRuntime = try LambdaRuntime(body: Self.handler())
6670
try await lambdaRuntime.run()
6771
}
6872
}

0 commit comments

Comments
 (0)