@@ -52,6 +52,7 @@ public protocol SCFHandler: EventLoopSCFHandler {
52
52
}
53
53
54
54
extension SCF {
55
+ @usableFromInline
55
56
internal static let defaultOffloadQueue = DispatchQueue ( label: " SCFHandler.offload " )
56
57
}
57
58
@@ -64,6 +65,7 @@ extension SCFHandler {
64
65
/// `SCFHandler` is offloading the processing to a `DispatchQueue`.
65
66
/// This is slower but safer, in case the implementation blocks the `EventLoop`.
66
67
/// Performance sensitive cloud functions should be based on `EventLoopSCFHandler` which does not offload.
68
+ @inlinable
67
69
public func handle( context: SCF . Context , event: In ) -> EventLoopFuture < Out > {
68
70
let promise = context. eventLoop. makePromise ( of: Out . self)
69
71
// FIXME: reusable DispatchQueue
@@ -140,18 +142,19 @@ public protocol EventLoopSCFHandler: ByteBufferSCFHandler {
140
142
141
143
extension EventLoopSCFHandler {
142
144
/// Driver for `ByteBuffer` -> `In` decoding and `Out` -> `ByteBuffer` encoding
145
+ @inlinable
143
146
public func handle( context: SCF . Context , event: ByteBuffer ) -> EventLoopFuture < ByteBuffer ? > {
144
- switch self . decodeIn ( buffer: event) {
145
- case . failure( let error) :
147
+ let input : In
148
+ do { input = try self . decode ( buffer: event) }
149
+ catch {
146
150
return context. eventLoop. makeFailedFuture ( CodecError . requestDecoding ( error) )
147
- case . success( let `in`) :
148
- return self . handle ( context: context, event: `in`) . flatMapThrowing { out in
149
- switch self . encodeOut ( allocator: context. allocator, value: out) {
150
- case . failure( let error) :
151
- throw CodecError . responseEncoding ( error)
152
- case . success( let buffer) :
153
- return buffer
154
- }
151
+ }
152
+
153
+ return self . handle ( context: context, event: input) . flatMapThrowing { output in
154
+ do {
155
+ return try self . encode ( allocator: context. allocator, value: output)
156
+ } catch {
157
+ throw CodecError . responseEncoding ( error)
155
158
}
156
159
}
157
160
}
@@ -175,6 +178,7 @@ extension EventLoopSCFHandler {
175
178
176
179
/// Implementation of `ByteBuffer` to `Void` decoding.
177
180
extension EventLoopSCFHandler where Out == Void {
181
+ @inlinable
178
182
public func encode( allocator: ByteBufferAllocator , value: Void ) throws -> ByteBuffer ? {
179
183
nil
180
184
}
@@ -212,7 +216,8 @@ extension ByteBufferSCFHandler {
212
216
}
213
217
}
214
218
215
- private enum CodecError : Error {
219
+ @usableFromInline
220
+ enum CodecError : Error {
216
221
case requestDecoding( Error )
217
222
case responseEncoding( Error )
218
223
}
0 commit comments