@@ -40,6 +40,7 @@ public protocol LambdaHandler: EventLoopLambdaHandler {
40
40
}
41
41
42
42
extension Lambda {
43
+ @usableFromInline
43
44
internal static let defaultOffloadQueue = DispatchQueue ( label: " LambdaHandler.offload " )
44
45
}
45
46
@@ -52,6 +53,7 @@ extension LambdaHandler {
52
53
/// `LambdaHandler` is offloading the processing to a `DispatchQueue`
53
54
/// This is slower but safer, in case the implementation blocks the `EventLoop`
54
55
/// Performance sensitive Lambdas should be based on `EventLoopLambdaHandler` which does not offload.
56
+ @inlinable
55
57
public func handle( context: Lambda . Context , event: In ) -> EventLoopFuture < Out > {
56
58
let promise = context. eventLoop. makePromise ( of: Out . self)
57
59
// FIXME: reusable DispatchQueue
@@ -128,41 +130,28 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler {
128
130
129
131
extension EventLoopLambdaHandler {
130
132
/// Driver for `ByteBuffer` -> `In` decoding and `Out` -> `ByteBuffer` encoding
133
+ @inlinable
131
134
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
148
136
do {
149
- return . success ( try self . decode ( buffer: buffer ) )
137
+ input = try self . decode ( buffer: event )
150
138
} catch {
151
- return . failure ( error)
139
+ return context . eventLoop . makeFailedFuture ( CodecError . requestDecoding ( error) )
152
140
}
153
- }
154
141
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
+ }
160
148
}
161
149
}
162
150
}
163
151
164
152
/// Implementation of `ByteBuffer` to `Void` decoding
165
153
extension EventLoopLambdaHandler where Out == Void {
154
+ @inlinable
166
155
public func encode( allocator: ByteBufferAllocator , value: Void ) throws -> ByteBuffer ? {
167
156
nil
168
157
}
@@ -200,7 +189,8 @@ extension ByteBufferLambdaHandler {
200
189
}
201
190
}
202
191
203
- private enum CodecError : Error {
192
+ @usableFromInline
193
+ enum CodecError : Error {
204
194
case requestDecoding( Error )
205
195
case responseEncoding( Error )
206
196
}
0 commit comments