Skip to content

Commit d778048

Browse files
authored
Enable Swift 6 mode! (#482)
1 parent 40e2291 commit d778048

File tree

6 files changed

+29
-23
lines changed

6 files changed

+29
-23
lines changed

Package.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ let package = Package(
3636
.product(name: "NIOCore", package: "swift-nio"),
3737
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
3838
.product(name: "NIOPosix", package: "swift-nio"),
39-
],
40-
swiftSettings: [.swiftLanguageMode(.v5)]
39+
]
4140
),
4241
.plugin(
4342
name: "AWSLambdaPackager",

Sources/AWSLambdaRuntime/Lambda+Codable.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ extension LambdaCodableAdapter {
6666
public init(
6767
encoder: JSONEncoder = JSONEncoder(),
6868
decoder: JSONDecoder = JSONDecoder(),
69-
handler: Handler
69+
handler: sending Handler
7070
)
7171
where
7272
Output: Encodable,

Sources/AWSLambdaRuntimeCore/Lambda+Codable.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public struct LambdaHandlerAdapter<
5858
/// Initializes an instance given a concrete handler.
5959
/// - Parameter handler: The ``LambdaHandler`` conforming handler that is to be adapted to ``LambdaWithBackgroundProcessingHandler``.
6060
@inlinable
61-
public init(handler: Handler) {
61+
public init(handler: sending Handler) {
6262
self.handler = handler
6363
}
6464

@@ -98,7 +98,7 @@ public struct LambdaCodableAdapter<
9898
/// - decoder: The decoder object that will be used to decode the received `ByteBuffer` event into the generic `Event` type served to the `handler`.
9999
/// - handler: The handler object.
100100
@inlinable
101-
public init(encoder: Encoder, decoder: Decoder, handler: Handler) where Output: Encodable {
101+
public init(encoder: sending Encoder, decoder: sending Decoder, handler: sending Handler) where Output: Encodable {
102102
self.encoder = encoder
103103
self.decoder = decoder
104104
self.handler = handler
@@ -109,7 +109,7 @@ public struct LambdaCodableAdapter<
109109
/// - decoder: The decoder object that will be used to decode the received `ByteBuffer` event into the generic `Event` type served to the `handler`.
110110
/// - handler: The handler object.
111111
@inlinable
112-
public init(decoder: Decoder, handler: Handler) where Output == Void, Encoder == VoidEncoder {
112+
public init(decoder: sending Decoder, handler: Handler) where Output == Void, Encoder == VoidEncoder {
113113
self.encoder = VoidEncoder()
114114
self.decoder = decoder
115115
self.handler = handler

Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift

+6-5
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,14 @@ private struct LambdaHttpServer {
174174
do {
175175
try await channel.executeThenClose { inbound, outbound in
176176
for try await inboundData in inbound {
177-
if case .head(let head) = inboundData {
177+
switch inboundData {
178+
case .head(let head):
178179
requestHead = head
179-
}
180-
if case .body(let body) = inboundData {
180+
181+
case .body(let body):
181182
requestBody = body
182-
}
183-
if case .end = inboundData {
183+
184+
case .end:
184185
precondition(requestHead != nil, "Received .end without .head")
185186
// process the request
186187
let response = try await self.processRequest(

Sources/AWSLambdaRuntimeCore/LambdaHandlers.swift

+9-7
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public struct ClosureHandler<Event: Decodable, Output>: LambdaHandler {
154154

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

@@ -192,8 +192,8 @@ extension LambdaRuntime {
192192
Encoder: LambdaOutputEncoder,
193193
Decoder: LambdaEventDecoder
194194
>(
195-
encoder: Encoder,
196-
decoder: Decoder,
195+
encoder: sending Encoder,
196+
decoder: sending Decoder,
197197
body: sending @escaping (Event, LambdaContext) async throws -> Output
198198
)
199199
where
@@ -205,21 +205,23 @@ extension LambdaRuntime {
205205
Encoder
206206
>
207207
{
208-
let handler = LambdaCodableAdapter(
208+
let closureHandler = ClosureHandler(body: body)
209+
let streamingAdapter = LambdaHandlerAdapter(handler: closureHandler)
210+
let codableWrapper = LambdaCodableAdapter(
209211
encoder: encoder,
210212
decoder: decoder,
211-
handler: LambdaHandlerAdapter(handler: ClosureHandler(body: body))
213+
handler: streamingAdapter
212214
)
213215

214-
self.init(handler: handler)
216+
self.init(handler: codableWrapper)
215217
}
216218

217219
/// Initialize an instance with a ``LambdaHandler`` defined in the form of a closure **with a `Void` return type**, an encoder, and a decoder.
218220
/// - Parameters:
219221
/// - decoder: The decoder object that will be used to decode the incoming `ByteBuffer` event into the generic `Event` type.
220222
/// - body: The handler in the form of a closure.
221223
public convenience init<Event: Decodable, Decoder: LambdaEventDecoder>(
222-
decoder: Decoder,
224+
decoder: sending Decoder,
223225
body: sending @escaping (Event, LambdaContext) async throws -> Void
224226
)
225227
where

Sources/AWSLambdaRuntimeCore/LambdaRuntimeClient.swift

+9-5
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,13 @@ final actor LambdaRuntimeClient: LambdaRuntimeClientProtocol {
4949
}
5050
}
5151

52+
private typealias ConnectionContinuation = CheckedContinuation<
53+
NIOLoopBound<LambdaChannelHandler<LambdaRuntimeClient>>, any Error
54+
>
55+
5256
private enum ConnectionState {
5357
case disconnected
54-
case connecting([CheckedContinuation<LambdaChannelHandler<LambdaRuntimeClient>, any Error>])
58+
case connecting([ConnectionContinuation])
5559
case connected(Channel, LambdaChannelHandler<LambdaRuntimeClient>)
5660
}
5761

@@ -158,7 +162,6 @@ final actor LambdaRuntimeClient: LambdaRuntimeClientProtocol {
158162
.sentResponse:
159163
fatalError("Invalid state: \(self.lambdaState)")
160164
}
161-
162165
}
163166

164167
private func write(_ buffer: NIOCore.ByteBuffer) async throws {
@@ -284,11 +287,11 @@ final actor LambdaRuntimeClient: LambdaRuntimeClientProtocol {
284287
case .connecting(var array):
285288
// Since we do get sequential invocations this case normally should never be hit.
286289
// We'll support it anyway.
287-
return try await withCheckedThrowingContinuation {
288-
(continuation: CheckedContinuation<LambdaChannelHandler<LambdaRuntimeClient>, any Error>) in
290+
let loopBound = try await withCheckedThrowingContinuation { (continuation: ConnectionContinuation) in
289291
array.append(continuation)
290292
self.connectionState = .connecting(array)
291293
}
294+
return loopBound.value
292295
case .connected(_, let handler):
293296
return handler
294297
}
@@ -339,8 +342,9 @@ final actor LambdaRuntimeClient: LambdaRuntimeClientProtocol {
339342
case .connecting(let array):
340343
self.connectionState = .connected(channel, handler)
341344
defer {
345+
let loopBound = NIOLoopBound(handler, eventLoop: self.eventLoop)
342346
for continuation in array {
343-
continuation.resume(returning: handler)
347+
continuation.resume(returning: loopBound)
344348
}
345349
}
346350
return handler

0 commit comments

Comments
 (0)