@@ -25,17 +25,27 @@ import NIO
25
25
/// The `EventLoopLambdaHandler` will execute the Lambda on the same `EventLoop` as the core runtime engine, making the processing faster but requires
26
26
/// more care from the implementation to never block the `EventLoop`.
27
27
public protocol LambdaHandler : EventLoopLambdaHandler {
28
+ @inlinable var dispatchQueue : DispatchQueue { get }
29
+
28
30
func handle( context: Lambda . Context , payload: In , callback: @escaping ( Result < Out , Error > ) -> Void )
29
31
}
30
32
33
+ private extension Lambda {
34
+ static let handlerQueue = DispatchQueue ( label: " LambdaHandler.offload " )
35
+ }
36
+
31
37
public extension LambdaHandler {
38
+ var dispatchQueue : DispatchQueue {
39
+ Lambda . handlerQueue
40
+ }
41
+
32
42
/// `LambdaHandler` is offloading the processing to a `DispatchQueue`
33
43
/// This is slower but safer, in case the implementation blocks the `EventLoop`
34
44
/// Performance sensitive Lambdas should be based on `EventLoopLambdaHandler` which does not offload.
35
45
func handle( context: Lambda . Context , payload: In ) -> EventLoopFuture < Out > {
36
46
let promise = context. eventLoop. makePromise ( of: Out . self)
37
47
// FIXME: reusable DispatchQueue
38
- DispatchQueue ( label : " LambdaHandler.offload " ) . async {
48
+ self . dispatchQueue . async {
39
49
self . handle ( context: context, payload: payload, callback: promise. completeWith)
40
50
}
41
51
return promise. futureResult
0 commit comments