Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
tomerd committed Apr 13, 2022
1 parent 39da6d9 commit c80f7c7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
18 changes: 16 additions & 2 deletions Sources/AWSLambdaRuntimeCore/LambdaHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,27 @@ extension LambdaHandler {

public func handle(_ event: Event, context: LambdaContext) -> EventLoopFuture<Output> {
let promise = context.eventLoop.makePromise(of: Output.self)
let handler = SendableHandler(underlying: self)
promise.completeWithTask {
try await self.handle(event, context: context)
try await handler.handle(event, context: context)
}
return promise.futureResult
}
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
fileprivate struct SendableHandler<Underlying: LambdaHandler>: @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
Expand Down Expand Up @@ -157,7 +171,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
Expand Down
6 changes: 0 additions & 6 deletions Sources/AWSLambdaRuntimeCore/Sendable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c80f7c7

Please sign in to comment.