File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed 
Sources/AWSLambdaRuntimeCore Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 1414
1515import  Foundation
1616import  Logging
17+ import  NIOConcurrencyHelpers
1718import  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
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments