Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ let package = Package(
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
.product(name: "NIOPosix", package: "swift-nio"),
],
swiftSettings: [.swiftLanguageMode(.v5)]
]
),
.plugin(
name: "AWSLambdaPackager",
Expand Down
2 changes: 1 addition & 1 deletion Sources/AWSLambdaRuntime/Lambda+Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extension LambdaCodableAdapter {
public init(
encoder: JSONEncoder = JSONEncoder(),
decoder: JSONDecoder = JSONDecoder(),
handler: Handler
handler: sending Handler
)
where
Output: Encodable,
Expand Down
6 changes: 3 additions & 3 deletions Sources/AWSLambdaRuntimeCore/Lambda+Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public struct LambdaHandlerAdapter<
/// Initializes an instance given a concrete handler.
/// - Parameter handler: The ``LambdaHandler`` conforming handler that is to be adapted to ``LambdaWithBackgroundProcessingHandler``.
@inlinable
public init(handler: Handler) {
public init(handler: sending Handler) {
self.handler = handler
}

Expand Down Expand Up @@ -98,7 +98,7 @@ public struct LambdaCodableAdapter<
/// - decoder: The decoder object that will be used to decode the received `ByteBuffer` event into the generic `Event` type served to the `handler`.
/// - handler: The handler object.
@inlinable
public init(encoder: Encoder, decoder: Decoder, handler: Handler) where Output: Encodable {
public init(encoder: sending Encoder, decoder: sending Decoder, handler: sending Handler) where Output: Encodable {
self.encoder = encoder
self.decoder = decoder
self.handler = handler
Expand All @@ -109,7 +109,7 @@ public struct LambdaCodableAdapter<
/// - decoder: The decoder object that will be used to decode the received `ByteBuffer` event into the generic `Event` type served to the `handler`.
/// - handler: The handler object.
@inlinable
public init(decoder: Decoder, handler: Handler) where Output == Void, Encoder == VoidEncoder {
public init(decoder: sending Decoder, handler: Handler) where Output == Void, Encoder == VoidEncoder {
self.encoder = VoidEncoder()
self.decoder = decoder
self.handler = handler
Expand Down
11 changes: 6 additions & 5 deletions Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,14 @@ private struct LambdaHttpServer {
do {
try await channel.executeThenClose { inbound, outbound in
for try await inboundData in inbound {
if case .head(let head) = inboundData {
switch inboundData {
case .head(let head):
requestHead = head
}
if case .body(let body) = inboundData {

case .body(let body):
requestBody = body
}
if case .end = inboundData {

case .end:
precondition(requestHead != nil, "Received .end without .head")
// process the request
let response = try await self.processRequest(
Expand Down
16 changes: 9 additions & 7 deletions Sources/AWSLambdaRuntimeCore/LambdaHandlers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public struct ClosureHandler<Event: Decodable, Output>: LambdaHandler {

/// Initialize with a closure handler over generic `Input` and `Output` types.
/// - Parameter body: The handler function written as a closure.
public init(body: @escaping (Event, LambdaContext) async throws -> Output) where Output: Encodable {
public init(body: sending @escaping (Event, LambdaContext) async throws -> Output) where Output: Encodable {
self.body = body
}

Expand Down Expand Up @@ -192,8 +192,8 @@ extension LambdaRuntime {
Encoder: LambdaOutputEncoder,
Decoder: LambdaEventDecoder
>(
encoder: Encoder,
decoder: Decoder,
encoder: sending Encoder,
decoder: sending Decoder,
body: sending @escaping (Event, LambdaContext) async throws -> Output
)
where
Expand All @@ -205,21 +205,23 @@ extension LambdaRuntime {
Encoder
>
{
let handler = LambdaCodableAdapter(
let closureHandler = ClosureHandler(body: body)
let streamingAdapter = LambdaHandlerAdapter(handler: closureHandler)
let codableWrapper = LambdaCodableAdapter(
encoder: encoder,
decoder: decoder,
handler: LambdaHandlerAdapter(handler: ClosureHandler(body: body))
handler: streamingAdapter
)

self.init(handler: handler)
self.init(handler: codableWrapper)
}

/// Initialize an instance with a ``LambdaHandler`` defined in the form of a closure **with a `Void` return type**, an encoder, and a decoder.
/// - Parameters:
/// - decoder: The decoder object that will be used to decode the incoming `ByteBuffer` event into the generic `Event` type.
/// - body: The handler in the form of a closure.
public convenience init<Event: Decodable, Decoder: LambdaEventDecoder>(
decoder: Decoder,
decoder: sending Decoder,
body: sending @escaping (Event, LambdaContext) async throws -> Void
)
where
Expand Down
11 changes: 6 additions & 5 deletions Sources/AWSLambdaRuntimeCore/LambdaRuntimeClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ final actor LambdaRuntimeClient: LambdaRuntimeClientProtocol {

private enum ConnectionState {
case disconnected
case connecting([CheckedContinuation<LambdaChannelHandler<LambdaRuntimeClient>, any Error>])
case connecting([CheckedContinuation<NIOLoopBound<LambdaChannelHandler<LambdaRuntimeClient>>, any Error>])
case connected(Channel, LambdaChannelHandler<LambdaRuntimeClient>)
}

Expand Down Expand Up @@ -158,7 +158,6 @@ final actor LambdaRuntimeClient: LambdaRuntimeClientProtocol {
.sentResponse:
fatalError("Invalid state: \(self.lambdaState)")
}

}

private func write(_ buffer: NIOCore.ByteBuffer) async throws {
Expand Down Expand Up @@ -284,11 +283,12 @@ final actor LambdaRuntimeClient: LambdaRuntimeClientProtocol {
case .connecting(var array):
// Since we do get sequential invocations this case normally should never be hit.
// We'll support it anyway.
return try await withCheckedThrowingContinuation {
(continuation: CheckedContinuation<LambdaChannelHandler<LambdaRuntimeClient>, any Error>) in
let loopBound = try await withCheckedThrowingContinuation {
(continuation: CheckedContinuation<NIOLoopBound<LambdaChannelHandler<LambdaRuntimeClient>>, any Error>) in
array.append(continuation)
self.connectionState = .connecting(array)
}
return loopBound.value
case .connected(_, let handler):
return handler
}
Expand Down Expand Up @@ -339,8 +339,9 @@ final actor LambdaRuntimeClient: LambdaRuntimeClientProtocol {
case .connecting(let array):
self.connectionState = .connected(channel, handler)
defer {
let loopBound = NIOLoopBound(handler, eventLoop: self.eventLoop)
for continuation in array {
continuation.resume(returning: handler)
continuation.resume(returning: loopBound)
}
}
return handler
Expand Down
Loading