13
13
//===----------------------------------------------------------------------===//
14
14
15
15
import Foundation
16
- //import ServiceLifecycle
17
16
import Logging
18
17
import NIOCore
19
- import Synchronization
18
+ import NIOConcurrencyHelpers
20
19
21
- package final class NewLambdaRuntime < Handler> : Sendable where Handler: StreamingLambdaHandler {
22
- 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
+ package final class NewLambdaRuntime < 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 < Optional < Handler > >
23
26
let logger : Logger
24
27
let eventLoop : EventLoop
25
28
@@ -28,7 +31,7 @@ package final class NewLambdaRuntime<Handler>: Sendable where Handler: Streaming
28
31
eventLoop: EventLoop = Lambda . defaultEventLoop,
29
32
logger: Logger = Logger ( label: " LambdaRuntime " )
30
33
) {
31
- self . handlerMutex = Mutex ( handler)
34
+ self . handlerMutex = NIOLockedValueBox ( handler)
32
35
self . eventLoop = eventLoop
33
36
self . logger = logger
34
37
}
@@ -42,11 +45,10 @@ package final class NewLambdaRuntime<Handler>: Sendable where Handler: Streaming
42
45
let ip = String ( ipAndPort [ 0 ] )
43
46
guard let port = Int ( ipAndPort [ 1 ] ) else { throw NewLambdaRuntimeError ( code: . invalidPort) }
44
47
45
- let handler = self . handlerMutex. withLock { maybeHandler in
46
- defer {
47
- maybeHandler = nil
48
- }
49
- return maybeHandler
48
+ let handler = self . handlerMutex. withLockedValue { handler in
49
+ let result = handler
50
+ handler = nil
51
+ return result
50
52
}
51
53
52
54
guard let handler else {
0 commit comments