promise: Capture stacktrace of timeout method caller in TimeoutException
Otherwise the stacktrace was from the executor thread which is not very
interesting. It is more interesting to know who called the timeout
method.
@@ -828,7 +828,11 @@ final class PromiseImpl<T> implements Promise<T> {
PromiseImpl<T> chained = new PromiseImpl<>(callbackExecutor,
scheduledExecutor);
if (!isDone()) {
- onResolve(chained.new Timeout(millis, TimeUnit.MILLISECONDS));
+ PromiseImpl<T> timedout = new PromiseImpl<>(null,
+ new TimeoutException(), callbackExecutor,
+ scheduledExecutor);
+ onResolve(new Timeout(chained.new Chain(timedout), millis,
+ TimeUnit.MILLISECONDS));
}
onResolve(chained.new Chain(this));
return chained;
@@ -844,8 +848,8 @@ final class PromiseImpl<T> implements Promise<T> {
private final class Timeout implements Runnable {
private final ScheduledFuture< ? > future;
- Timeout(long timeout, TimeUnit unit) {
- future = schedule(new TimeoutAction(), timeout, unit);
+ Timeout(Runnable operation, long delay, TimeUnit unit) {
+ future = schedule(operation, delay, unit);
}
@Override
@@ -856,21 +860,6 @@ final class PromiseImpl<T> implements Promise<T> {
}
}
- /**
- * Callback used to fail the Promise if the timeout expires.
- *
- * @Immutable
- * @since 1.1
- */
- private final class TimeoutAction implements Runnable {
- TimeoutAction() {}
-
- @Override
- public void run() {
- tryResolve(null, new TimeoutException());
- }
- }
-
/**
* {@inheritDoc}
*
