Skip to content

Commit 28d613b

Browse files
committed
fixup
1 parent 39da6d9 commit 28d613b

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

Sources/AWSLambdaRuntimeCore/LambdaHandler.swift

+18-2
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,29 @@ extension LambdaHandler {
5858

5959
public func handle(_ event: Event, context: LambdaContext) -> EventLoopFuture<Output> {
6060
let promise = context.eventLoop.makePromise(of: Output.self)
61+
// using an unchecked sendable wrapper for the handler
62+
// this is safe since lambda runtime is designed to calls the handler serially
63+
let handler = UncheckedSendableHandler(underlying: self)
6164
promise.completeWithTask {
62-
try await self.handle(event, context: context)
65+
try await handler.handle(event, context: context)
6366
}
6467
return promise.futureResult
6568
}
6669
}
6770

71+
/// unchecked sendable wrapper for the handler
72+
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
73+
fileprivate struct UncheckedSendableHandler<Underlying: LambdaHandler>: @unchecked Sendable {
74+
let underlying: Underlying
75+
76+
init(underlying: Underlying) {
77+
self.underlying = underlying
78+
}
79+
80+
func handle(_ event: Underlying.Event, context: LambdaContext) async throws -> Underlying.Output {
81+
try await self.underlying.handle(event, context: context)
82+
}
83+
}
6884
#endif
6985

7086
// MARK: - EventLoopLambdaHandler
@@ -157,7 +173,7 @@ extension EventLoopLambdaHandler where Output == Void {
157173
/// - note: This is a low level protocol designed to power the higher level ``EventLoopLambdaHandler`` and
158174
/// ``LambdaHandler`` based APIs.
159175
/// Most users are not expected to use this protocol.
160-
public protocol ByteBufferLambdaHandler: _ByteBufferLambdaHandlerSendable {
176+
public protocol ByteBufferLambdaHandler {
161177
/// Create your Lambda handler for the runtime.
162178
///
163179
/// Use this to initialize all your resources that you want to cache between invocations. This could be database

Sources/AWSLambdaRuntimeCore/Sendable.swift

-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414

1515
// Sendable bridging types
1616

17-
#if compiler(>=5.6)
18-
@preconcurrency public protocol _ByteBufferLambdaHandlerSendable: Sendable {}
19-
#else
20-
public protocol _ByteBufferLambdaHandlerSendable {}
21-
#endif
22-
2317
#if compiler(>=5.6)
2418
public typealias _AWSLambdaSendable = Sendable
2519
#else

docker/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN echo 'export PATH="$HOME/.tools:$PATH"' >> $HOME/.profile
1515

1616
# swiftformat (until part of the toolchain)
1717

18-
ARG swiftformat_version=0.49.6
18+
ARG swiftformat_version=0.47.3
1919
RUN git clone --branch $swiftformat_version --depth 1 https://github.com/nicklockwood/SwiftFormat $HOME/.tools/swift-format
2020
RUN cd $HOME/.tools/swift-format && swift build -c release
2121
RUN ln -s $HOME/.tools/swift-format/.build/release/swiftformat $HOME/.tools/swiftformat

0 commit comments

Comments
 (0)