diff --git a/Sources/AWSLambdaRuntimeCore/Lambda.swift b/Sources/AWSLambdaRuntimeCore/Lambda.swift index d54d0192..ed41dbac 100644 --- a/Sources/AWSLambdaRuntimeCore/Lambda.swift +++ b/Sources/AWSLambdaRuntimeCore/Lambda.swift @@ -23,6 +23,14 @@ import Logging import NIOCore import NIOPosix +// Workaround for earlier Swift versions. +// Remove and replace `LambdaSendable` with `Sendable` once we fully embrace concurrency. +#if swift(>=5.5) && canImport(_Concurrency) +public typealias LambdaSendable = Swift.Sendable +#else +public typealias LambdaSendable = Any +#endif + public enum Lambda { public typealias Handler = ByteBufferLambdaHandler diff --git a/Sources/AWSLambdaRuntimeCore/LambdaContext.swift b/Sources/AWSLambdaRuntimeCore/LambdaContext.swift index ca4af5c6..0cfdeac5 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaContext.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaContext.swift @@ -21,7 +21,7 @@ import NIOCore extension Lambda { /// Lambda runtime initialization context. /// The Lambda runtime generates and passes the `InitializationContext` to the Lambda factory as an argument. - public struct InitializationContext { + public struct InitializationContext: LambdaSendable { /// `Logger` to log with /// /// - note: The `LogLevel` can be configured using the `LOG_LEVEL` environment variable. @@ -60,7 +60,7 @@ extension Lambda { /// Lambda runtime context. /// The Lambda runtime generates and passes the `Context` to the Lambda handler as an argument. -public struct LambdaContext: CustomDebugStringConvertible { +public struct LambdaContext: CustomDebugStringConvertible, LambdaSendable { final class _Storage { var requestID: String var traceID: String diff --git a/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift b/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift index f0a9d256..0cc9749f 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift @@ -20,7 +20,7 @@ import NIOCore #if compiler(>=5.5) && canImport(_Concurrency) /// Strongly typed, processing protocol for a Lambda that takes a user defined `Event` and returns a user defined `Output` async. @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) -public protocol LambdaHandler: EventLoopLambdaHandler { +public protocol LambdaHandler: EventLoopLambdaHandler, Sendable { /// The Lambda initialization method /// Use this method to initialize resources that will be used in every request. /// @@ -69,7 +69,7 @@ extension LambdaHandler { /// The `EventLoopLambdaHandler` will execute the Lambda on the same `EventLoop` as the core runtime engine, making the processing faster but requires /// more care from the implementation to never block the `EventLoop`. public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler { - associatedtype Event + associatedtype Event: LambdaSendable associatedtype Output /// The Lambda handling method