package io.tetrapod.core.rpc;

import io.tetrapod.core.Session;
import io.tetrapod.protocol.core.RequestHeader;

import org.slf4j.*;

public class Async {
   public static final Logger logger   = LoggerFactory.getLogger(Async.class);

   public final long          sendTime = System.currentTimeMillis();
   public final RequestHeader header;
   public final Request       request;
   public final Session       session;

   private Response           response;
   private ResponseHandler    handler;

   public Async(Request request, RequestHeader header, Session session) {
      this.request = request;
      this.header = header;
      this.session = session;
   }

   public Async(Request request, RequestHeader header, Session session, ResponseHandler handler) {
      this(request, header, session);
      this.handler = handler;
   }

   public synchronized boolean hasHandler() {
      return handler != null;
   }

   public synchronized void handle(ResponseHandler handler) {
      this.handler = handler;
      if (response != null) {
         handler.fireResponse(response, header);
      }
   }

   public synchronized void setResponse(int errorCode) {
      setResponse(new Error(errorCode));
   }

   public synchronized void setResponse(Response res) {
      response = res;
      if (handler != null) {
         try {
            handler.fireResponse(res, header);
         } catch (Throwable e) {
            logger.error(e.getMessage(), e);
         }
      }
      notifyAll();
   }

   public boolean isTimedout() {
      return System.currentTimeMillis() - sendTime > header.timeout * 1000;
   }

   public synchronized Response waitForResponse() {
      while (response == null) {
         try {
            wait(1000);
         } catch (InterruptedException e) {}
      }
      return response;
   }

   public void log() {
      handle(ResponseHandler.LOGGER);
   }

}

@@ -94,42 +94,126 @@
 ore.
-RequestHeader;%0A%0Aimport org.slf4j.*
+CoreContract;%0Aimport io.tetrapod.protocol.core.RequestHeader;%0A%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory
 ;%0A%0Ap
@@ -1865,16 +1865,96 @@
 n e) %7B%7D%0A
+         if (isTimedout())%0A            setResponse(CoreContract.ERROR_TIMEOUT);%0A
       %7D%0A

Make sure waitForResponse() will eventually return if the system doesn't properly time it out for some reason