From 28d613b095679fee4e70be6979e7e11425f25e0a Mon Sep 17 00:00:00 2001 From: tom doron Date: Tue, 12 Apr 2022 18:26:38 -0700 Subject: [PATCH] fixup --- .../AWSLambdaRuntimeCore/LambdaHandler.swift | 20 +++++++++++++++++-- Sources/AWSLambdaRuntimeCore/Sendable.swift | 6 ------ docker/Dockerfile | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift b/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift index a78f0f92..7a2dd77e 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift @@ -58,13 +58,29 @@ extension LambdaHandler { public func handle(_ event: Event, context: LambdaContext) -> EventLoopFuture { let promise = context.eventLoop.makePromise(of: Output.self) + // using an unchecked sendable wrapper for the handler + // this is safe since lambda runtime is designed to calls the handler serially + let handler = UncheckedSendableHandler(underlying: self) promise.completeWithTask { - try await self.handle(event, context: context) + try await handler.handle(event, context: context) } return promise.futureResult } } +/// unchecked sendable wrapper for the handler +@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) +fileprivate struct UncheckedSendableHandler: @unchecked Sendable { + let underlying: Underlying + + init(underlying: Underlying) { + self.underlying = underlying + } + + func handle(_ event: Underlying.Event, context: LambdaContext) async throws -> Underlying.Output { + try await self.underlying.handle(event, context: context) + } +} #endif // MARK: - EventLoopLambdaHandler @@ -157,7 +173,7 @@ extension EventLoopLambdaHandler where Output == Void { /// - note: This is a low level protocol designed to power the higher level ``EventLoopLambdaHandler`` and /// ``LambdaHandler`` based APIs. /// Most users are not expected to use this protocol. -public protocol ByteBufferLambdaHandler: _ByteBufferLambdaHandlerSendable { +public protocol ByteBufferLambdaHandler { /// Create your Lambda handler for the runtime. /// /// Use this to initialize all your resources that you want to cache between invocations. This could be database diff --git a/Sources/AWSLambdaRuntimeCore/Sendable.swift b/Sources/AWSLambdaRuntimeCore/Sendable.swift index 3c4d1c40..936403e4 100644 --- a/Sources/AWSLambdaRuntimeCore/Sendable.swift +++ b/Sources/AWSLambdaRuntimeCore/Sendable.swift @@ -14,12 +14,6 @@ // Sendable bridging types -#if compiler(>=5.6) -@preconcurrency public protocol _ByteBufferLambdaHandlerSendable: Sendable {} -#else -public protocol _ByteBufferLambdaHandlerSendable {} -#endif - #if compiler(>=5.6) public typealias _AWSLambdaSendable = Sendable #else diff --git a/docker/Dockerfile b/docker/Dockerfile index fdd8b74f..9979f708 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -15,7 +15,7 @@ RUN echo 'export PATH="$HOME/.tools:$PATH"' >> $HOME/.profile # swiftformat (until part of the toolchain) -ARG swiftformat_version=0.49.6 +ARG swiftformat_version=0.47.3 RUN git clone --branch $swiftformat_version --depth 1 https://github.com/nicklockwood/SwiftFormat $HOME/.tools/swift-format RUN cd $HOME/.tools/swift-format && swift build -c release RUN ln -s $HOME/.tools/swift-format/.build/release/swiftformat $HOME/.tools/swiftformat