Skip to content

Enable Swift 6 mode! #482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 9 additions & 5 deletions Sources/AWSLambdaRuntimeCore/LambdaRuntimeClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ final actor LambdaRuntimeClient: LambdaRuntimeClientProtocol {
}
}

private typealias ConnectionContinuation = CheckedContinuation<
NIOLoopBound<LambdaChannelHandler<LambdaRuntimeClient>>, any Error
>

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

Expand Down Expand Up @@ -158,7 +162,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 +287,11 @@ 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: ConnectionContinuation) in
array.append(continuation)
self.connectionState = .connecting(array)
}
return loopBound.value
case .connected(_, let handler):
return handler
}
Expand Down Expand Up @@ -339,8 +342,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