diff --git a/src/Deferred.java b/src/Deferred.java index 9a02a52..e872e3d 100644 --- a/src/Deferred.java +++ b/src/Deferred.java @@ -1130,6 +1130,7 @@ private T doJoin(final boolean interruptible, final long timeout) try { while (true) { try { + boolean timedout = false; synchronized (signal_cb) { addBoth((Callback) ((Object) signal_cb)); if (timeout == 0) { // No timeout, we can use a simple loop. @@ -1174,12 +1175,15 @@ private T doJoin(final boolean interruptible, final long timeout) // But entering `wait' is pretty much guaranteed to make the // loop take more than 100ns no matter what. if (timeleft < 100) { - throw new TimeoutException(this, timeout); + timedout = true; + break; } } } } - if (signal_cb.result instanceof Exception) { + if (timedout) { + throw new TimeoutException(this, timeout); + } else if (signal_cb.result instanceof Exception) { throw (Exception) signal_cb.result; } return (T) signal_cb.result;