@@ -38,8 +38,7 @@ struct LambdaMockWriter: LambdaResponseStreamWriter {
38
38
}
39
39
40
40
func reportError( _ error: any Error ) async throws {
41
- try await self . underlying. write ( ByteBuffer ( string: " \( error) " ) )
42
- try await self . underlying. finish ( )
41
+ await self . underlying. reportError ( error)
43
42
}
44
43
}
45
44
@@ -105,6 +104,12 @@ final actor LambdaMockClient: LambdaRuntimeClientProtocol {
105
104
case fail( LambdaError )
106
105
}
107
106
107
+ enum CancelProcessingAction {
108
+ case none
109
+
110
+ case cancelContinuation( CheckedContinuation < ByteBuffer , any Error > )
111
+ }
112
+
108
113
mutating func next( _ eventArrivedHandler: CheckedContinuation < Invocation , any Error > ) -> NextAction {
109
114
switch self . state {
110
115
case . initialState:
@@ -185,6 +190,15 @@ final actor LambdaMockClient: LambdaRuntimeClientProtocol {
185
190
return . cancelContinuation( eventArrivedHandler)
186
191
}
187
192
}
193
+
194
+ mutating func cancelProcessing( ) -> CancelProcessingAction {
195
+ switch self . state {
196
+ case . initialState, . waitingForNextEvent:
197
+ return . none
198
+ case . handlerIsProcessing( _, let eventProcessedHandler) :
199
+ return . cancelContinuation( eventProcessedHandler)
200
+ }
201
+ }
188
202
}
189
203
190
204
private var stateMachine : StateMachine = . init( )
@@ -268,4 +282,13 @@ final actor LambdaMockClient: LambdaRuntimeClientProtocol {
268
282
func finish( ) async throws {
269
283
try self . stateMachine. finish ( )
270
284
}
285
+
286
+ func reportError( _ error: any Error ) {
287
+ switch self . stateMachine. cancelProcessing ( ) {
288
+ case . none:
289
+ break
290
+ case . cancelContinuation( let continuation) :
291
+ continuation. resume ( throwing: error)
292
+ }
293
+ }
271
294
}
0 commit comments