@@ -203,14 +203,7 @@ void handleMessage(String requestId, Function<StreamingMessage, StreamingMessage
203203 this .getResponseCondition (requestId ).await (RESPONSE_POLL_MILLIS , TimeUnit .MILLISECONDS );
204204 FunctionsTestHost .this .throwIfListeningFailed ();
205205 }
206- StreamingMessage message = this .respValue .get (requestId );
207- StreamingMessage response = null ;
208- if (handler != null ) {
209- response = handler .apply (message );
210- }
211- if (response != null ) {
212- this .responder .get (requestId ).onNext (response );
213- }
206+ this .respondToMessage (requestId , handler );
214207 } finally {
215208 this .lock .unlock ();
216209 }
@@ -230,19 +223,23 @@ void handleMessageWithTimeout(String requestId, Function<StreamingMessage, Strea
230223 long waitMillis = Math .max (1L , Math .min (TimeUnit .NANOSECONDS .toMillis (remainingNanos ), RESPONSE_POLL_MILLIS ));
231224 this .getResponseCondition (requestId ).await (waitMillis , TimeUnit .MILLISECONDS );
232225 }
233- StreamingMessage message = this .respValue .get (requestId );
234- StreamingMessage response = null ;
235- if (handler != null ) {
236- response = handler .apply (message );
237- }
238- if (response != null ) {
239- this .responder .get (requestId ).onNext (response );
240- }
226+ this .respondToMessage (requestId , handler );
241227 } finally {
242228 this .lock .unlock ();
243229 }
244230 }
245231
232+ private void respondToMessage (String requestId , Function <StreamingMessage , StreamingMessage > handler ) {
233+ StreamingMessage message = this .respValue .get (requestId );
234+ StreamingMessage response = null ;
235+ if (handler != null ) {
236+ response = handler .apply (message );
237+ }
238+ if (response != null ) {
239+ this .responder .get (requestId ).onNext (response );
240+ }
241+ }
242+
246243 private StreamingMessage initWorker () {
247244 WorkerInitRequest .Builder request = WorkerInitRequest .newBuilder ().setHostVersion ("2.0.0" );
248245 return StreamingMessage .newBuilder ().setRequestId (INITWORKER_REQID ).setWorkerInitRequest (request ).build ();
0 commit comments