Skip to content

Commit 355cd16

Browse files
authored
Merge branch 'main' into sebsto/docker
2 parents 17dcfcc + a8eadf4 commit 355cd16

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift

+9-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414

1515
import Foundation
1616
import Logging
17+
import NIOConcurrencyHelpers
1718
import NIOCore
18-
import Synchronization
1919

20-
public final class LambdaRuntime<Handler>: Sendable where Handler: StreamingLambdaHandler {
21-
let handlerMutex: Mutex<Handler?>
20+
// We need `@unchecked` Sendable here, as `NIOLockedValueBox` does not understand `sending` today.
21+
// We don't want to use `NIOLockedValueBox` here anyway. We would love to use Mutex here, but this
22+
// sadly crashes the compiler today.
23+
public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: StreamingLambdaHandler {
24+
// TODO: We want to change this to Mutex as soon as this doesn't crash the Swift compiler on Linux anymore
25+
let handlerMutex: NIOLockedValueBox<Handler?>
2226
let logger: Logger
2327
let eventLoop: EventLoop
2428

@@ -27,7 +31,7 @@ public final class LambdaRuntime<Handler>: Sendable where Handler: StreamingLamb
2731
eventLoop: EventLoop = Lambda.defaultEventLoop,
2832
logger: Logger = Logger(label: "LambdaRuntime")
2933
) {
30-
self.handlerMutex = Mutex(handler)
34+
self.handlerMutex = NIOLockedValueBox(handler)
3135
self.eventLoop = eventLoop
3236
self.logger = logger
3337
}
@@ -41,7 +45,7 @@ public final class LambdaRuntime<Handler>: Sendable where Handler: StreamingLamb
4145
let ip = String(ipAndPort[0])
4246
guard let port = Int(ipAndPort[1]) else { throw LambdaRuntimeError(code: .invalidPort) }
4347

44-
let handler = self.handlerMutex.withLock { handler in
48+
let handler = self.handlerMutex.withLockedValue { handler in
4549
let result = handler
4650
handler = nil
4751
return result

0 commit comments

Comments
 (0)