Skip to content

Commit 0b4b92d

Browse files
committed
Opt into Swift 6 language mode for most targets
1 parent 600e48c commit 0b4b92d

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

Package.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ let package = Package(
3333
.byName(name: "AWSLambdaRuntimeCore"),
3434
.product(name: "NIOCore", package: "swift-nio"),
3535
.product(name: "NIOFoundationCompat", package: "swift-nio"),
36-
],
37-
swiftSettings: [.swiftLanguageMode(.v5)]
36+
]
3837
),
3938
.target(
4039
name: "AWSLambdaRuntimeCore",

Sources/AWSLambdaRuntime/Lambda+Codable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ extension LambdaRuntime {
7171
/// - Parameter encoder: The encoder object that will be used to encode the generic `Output` into a `ByteBuffer`. `JSONEncoder()` used as default.
7272
/// - Parameter decoder: The decoder object that will be used to decode the incoming `ByteBuffer` event into the generic `Event` type. `JSONDecoder()` used as default.
7373
public convenience init<Event: Decodable, Output>(
74-
body: @escaping (Event, LambdaContext) async throws -> Output,
74+
body: sending @escaping (Event, LambdaContext) async throws -> Output,
7575
encoder: JSONEncoder = JSONEncoder(),
7676
decoder: JSONDecoder = JSONDecoder()
7777
)
@@ -97,7 +97,7 @@ extension LambdaRuntime {
9797
/// - Parameter body: The handler in the form of a closure.
9898
/// - Parameter decoder: The decoder object that will be used to decode the incoming `ByteBuffer` event into the generic `Event` type. `JSONDecoder()` used as default.
9999
public convenience init<Event: Decodable>(
100-
body: @escaping (Event, LambdaContext) async throws -> Void,
100+
body: sending @escaping (Event, LambdaContext) async throws -> Void,
101101
decoder: JSONDecoder = JSONDecoder()
102102
)
103103
where

Sources/AWSLambdaRuntimeCore/Lambda.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public enum Lambda {
6060
}
6161

6262
/// The default EventLoop the Lambda is scheduled on.
63-
public static var defaultEventLoop: any EventLoop = NIOSingletons.posixEventLoopGroup.next()
63+
public static let defaultEventLoop: any EventLoop = NIOSingletons.posixEventLoopGroup.next()
6464
}
6565

6666
// MARK: - Public API

Tests/AWSLambdaRuntimeCoreTests/MockLambdaServer.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func withMockServer<Result>(
2727
_ body: (_ port: Int) async throws -> Result
2828
) async throws -> Result {
2929
let eventLoopGroup = NIOSingletons.posixEventLoopGroup
30-
let server = MockLambdaServer(behavior: behaviour, port: port, keepAlive: keepAlive)
30+
let server = MockLambdaServer(behavior: behaviour, port: port, keepAlive: keepAlive, eventLoopGroup: eventLoopGroup)
3131
let port = try await server.start().get()
3232

3333
let result: Swift.Result<Result, any Error>
@@ -52,7 +52,13 @@ final class MockLambdaServer {
5252
private var channel: Channel?
5353
private var shutdown = false
5454

55-
init(behavior: LambdaServerBehavior, host: String = "127.0.0.1", port: Int = 7000, keepAlive: Bool = true) {
55+
init(
56+
behavior: LambdaServerBehavior,
57+
host: String = "127.0.0.1",
58+
port: Int = 7000,
59+
keepAlive: Bool = true,
60+
eventLoopGroup: MultiThreadedEventLoopGroup
61+
) {
5662
self.group = NIOSingletons.posixEventLoopGroup
5763
self.behavior = behavior
5864
self.host = host
@@ -233,11 +239,14 @@ final class HTTPHandler: ChannelInboundHandler {
233239
}
234240
}
235241

242+
let loopBoundContext = NIOLoopBound(context, eventLoop: context.eventLoop)
243+
236244
context.writeAndFlush(wrapOutboundOut(.end(nil))).whenComplete { result in
237245
if case .failure(let error) = result {
238246
self.logger.error("\(self) write error \(error)")
239247
}
240248
if !self.keepAlive {
249+
let context = loopBoundContext.value
241250
context.close().whenFailure { error in
242251
self.logger.error("\(self) close error \(error)")
243252
}

0 commit comments

Comments
 (0)