@@ -40,6 +40,7 @@ public protocol LambdaHandler: EventLoopLambdaHandler {
4040}
4141
4242extension Lambda {
43+ @usableFromInline
4344 internal static let defaultOffloadQueue = DispatchQueue ( label: " LambdaHandler.offload " )
4445}
4546
@@ -52,6 +53,7 @@ extension LambdaHandler {
5253 /// `LambdaHandler` is offloading the processing to a `DispatchQueue`
5354 /// This is slower but safer, in case the implementation blocks the `EventLoop`
5455 /// Performance sensitive Lambdas should be based on `EventLoopLambdaHandler` which does not offload.
56+ @inlinable
5557 public func handle( context: Lambda . Context , event: In ) -> EventLoopFuture < Out > {
5658 let promise = context. eventLoop. makePromise ( of: Out . self)
5759 // FIXME: reusable DispatchQueue
@@ -128,41 +130,28 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler {
128130
129131extension EventLoopLambdaHandler {
130132 /// Driver for `ByteBuffer` -> `In` decoding and `Out` -> `ByteBuffer` encoding
133+ @inlinable
131134 public func handle( context: Lambda . Context , event: ByteBuffer ) -> EventLoopFuture < ByteBuffer ? > {
132- switch self . decodeIn ( buffer: event) {
133- case . failure( let error) :
134- return context. eventLoop. makeFailedFuture ( CodecError . requestDecoding ( error) )
135- case . success( let `in`) :
136- return self . handle ( context: context, event: `in`) . flatMapThrowing { out in
137- switch self . encodeOut ( allocator: context. allocator, value: out) {
138- case . failure( let error) :
139- throw CodecError . responseEncoding ( error)
140- case . success( let buffer) :
141- return buffer
142- }
143- }
144- }
145- }
146-
147- private func decodeIn( buffer: ByteBuffer ) -> Result < In , Error > {
135+ let input : In
148136 do {
149- return . success ( try self . decode ( buffer: buffer ) )
137+ input = try self . decode ( buffer: event )
150138 } catch {
151- return . failure ( error)
139+ return context . eventLoop . makeFailedFuture ( CodecError . requestDecoding ( error) )
152140 }
153- }
154141
155- private func encodeOut( allocator: ByteBufferAllocator , value: Out ) -> Result < ByteBuffer ? , Error > {
156- do {
157- return . success( try self . encode ( allocator: allocator, value: value) )
158- } catch {
159- return . failure( error)
142+ return self . handle ( context: context, event: input) . flatMapThrowing { output in
143+ do {
144+ return try self . encode ( allocator: context. allocator, value: output)
145+ } catch {
146+ throw CodecError . responseEncoding ( error)
147+ }
160148 }
161149 }
162150}
163151
164152/// Implementation of `ByteBuffer` to `Void` decoding
165153extension EventLoopLambdaHandler where Out == Void {
154+ @inlinable
166155 public func encode( allocator: ByteBufferAllocator , value: Void ) throws -> ByteBuffer ? {
167156 nil
168157 }
@@ -200,7 +189,8 @@ extension ByteBufferLambdaHandler {
200189 }
201190}
202191
203- private enum CodecError : Error {
192+ @usableFromInline
193+ enum CodecError : Error {
204194 case requestDecoding( Error )
205195 case responseEncoding( Error )
206196}
0 commit comments