Skip to content

Commit 2c002cc

Browse files
fabianfettsebsto
andauthored
Use Mutex instead of NIOLockedValueBox (swift-server#394)
* Use Mutex instead of NIOLockedValueBox * fix format --------- Co-authored-by: Sébastien Stormacq <sebastien.stormacq@gmail.com>
1 parent 4295e51 commit 2c002cc

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift

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

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

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?>
20+
public final class LambdaRuntime<Handler>: Sendable where Handler: StreamingLambdaHandler {
21+
let handlerMutex: Mutex<Handler?>
2622
let logger: Logger
2723
let eventLoop: EventLoop
2824

@@ -31,7 +27,7 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
3127
eventLoop: EventLoop = Lambda.defaultEventLoop,
3228
logger: Logger = Logger(label: "LambdaRuntime")
3329
) {
34-
self.handlerMutex = NIOLockedValueBox(handler)
30+
self.handlerMutex = Mutex(handler)
3531
self.eventLoop = eventLoop
3632
self.logger = logger
3733
}
@@ -45,7 +41,7 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
4541
let ip = String(ipAndPort[0])
4642
guard let port = Int(ipAndPort[1]) else { throw LambdaRuntimeError(code: .invalidPort) }
4743

48-
let handler = self.handlerMutex.withLockedValue { handler in
44+
let handler = self.handlerMutex.withLock { handler in
4945
let result = handler
5046
handler = nil
5147
return result

0 commit comments

Comments
 (0)