1313//===----------------------------------------------------------------------===//
1414
1515import Logging
16- import NIOConcurrencyHelpers
1716import NIOCore
17+ import Synchronization
1818
1919#if canImport(FoundationEssentials)
2020import FoundationEssentials
2121#else
2222import Foundation
2323#endif
2424
25- // We need `@unchecked` Sendable here, as `NIOLockedValueBox` does not understand `sending` today.
26- // We don't want to use `NIOLockedValueBox` here anyway. We would love to use Mutex here, but this
27- // sadly crashes the compiler today.
25+ // We need `@unchecked` Sendable here until we can make `Handler` `Sendable`.
2826public final class LambdaRuntime < Handler> : @unchecked Sendable where Handler: StreamingLambdaHandler {
29- // TODO: We want to change this to Mutex as soon as this doesn't crash the Swift compiler on Linux anymore
30- let handlerMutex : NIOLockedValueBox < Handler ? >
27+ let handlerMutex : Mutex < Handler ? > = Mutex ( nil )
3128
3229 let logger : Logger
3330 let eventLoop : EventLoop
@@ -37,7 +34,8 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
3734 eventLoop: EventLoop = Lambda . defaultEventLoop,
3835 logger: Logger = Logger ( label: " LambdaRuntime " )
3936 ) {
40- self . handlerMutex = NIOLockedValueBox ( handler)
37+
38+ handlerMutex. withLock { $0 = handler }
4139 self . eventLoop = eventLoop
4240
4341 // by setting the log level here, we understand it can not be changed dynamically at runtime
@@ -50,11 +48,7 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
5048 }
5149
5250 public func run( ) async throws {
53- let handler = self . handlerMutex. withLockedValue { handler in
54- let result = handler
55- handler = nil
56- return result
57- }
51+ let handler = self . handlerMutex. withLock { $0 }
5852
5953 guard let handler else {
6054 throw LambdaRuntimeError ( code: . runtimeCanOnlyBeStartedOnce)
0 commit comments