File tree 1 file changed +9
-5
lines changed
Sources/AWSLambdaRuntimeCore
1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 14
14
15
15
import Foundation
16
16
import Logging
17
+ import NIOConcurrencyHelpers
17
18
import NIOCore
18
- import Synchronization
19
19
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 ? >
22
26
let logger : Logger
23
27
let eventLoop : EventLoop
24
28
@@ -27,7 +31,7 @@ public final class LambdaRuntime<Handler>: Sendable where Handler: StreamingLamb
27
31
eventLoop: EventLoop = Lambda . defaultEventLoop,
28
32
logger: Logger = Logger ( label: " LambdaRuntime " )
29
33
) {
30
- self . handlerMutex = Mutex ( handler)
34
+ self . handlerMutex = NIOLockedValueBox ( handler)
31
35
self . eventLoop = eventLoop
32
36
self . logger = logger
33
37
}
@@ -41,7 +45,7 @@ public final class LambdaRuntime<Handler>: Sendable where Handler: StreamingLamb
41
45
let ip = String ( ipAndPort [ 0 ] )
42
46
guard let port = Int ( ipAndPort [ 1 ] ) else { throw LambdaRuntimeError ( code: . invalidPort) }
43
47
44
- let handler = self . handlerMutex. withLock { handler in
48
+ let handler = self . handlerMutex. withLockedValue { handler in
45
49
let result = handler
46
50
handler = nil
47
51
return result
You can’t perform that action at this time.
0 commit comments