Close future's continuation on cancel even if future itself was not cancelled

This commit is contained in:
Nikolay Martynov 2019-02-08 16:58:54 -05:00
parent 9d830a3dab
commit 3a0a471dd5
1 changed files with 9 additions and 9 deletions

View File

@ -102,15 +102,15 @@ public final class FutureInstrumentation extends Instrumenter.Default {
public static class CanceledFutureAdvice { public static class CanceledFutureAdvice {
@Advice.OnMethodExit(suppress = Throwable.class) @Advice.OnMethodExit(suppress = Throwable.class)
public static void exit( public static void exit(@Advice.This final Future<?> future) {
@Advice.This final Future<?> future, @Advice.Return final boolean canceled) { // Try to close continuation even if future was not cancelled:
if (canceled) { // the expectation is that continuation should be closed after 'cancel'
final ContextStore<Future, State> contextStore = // is called, one way or another
InstrumentationContext.get(Future.class, State.class); final ContextStore<Future, State> contextStore =
final State state = contextStore.get(future); InstrumentationContext.get(Future.class, State.class);
if (state != null) { final State state = contextStore.get(future);
state.closeContinuation(); if (state != null) {
} state.closeContinuation();
} }
} }
} }