From 5dcd812e4d103316dc5d5a1a92f184e0a2d0d163 Mon Sep 17 00:00:00 2001 From: EricLin Date: Sun, 21 Jul 2024 13:53:04 +0800 Subject: [PATCH] fix ListenableFutureUtils#toCompletableFuture cancellation propagation --- .../main/java/io/foldright/cffu/ListenableFutureUtils.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cffu-core/src/main/java/io/foldright/cffu/ListenableFutureUtils.java b/cffu-core/src/main/java/io/foldright/cffu/ListenableFutureUtils.java index 71779d47..332db4f2 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/ListenableFutureUtils.java +++ b/cffu-core/src/main/java/io/foldright/cffu/ListenableFutureUtils.java @@ -50,7 +50,12 @@ public String toString() { } }; // propagate cancellation by CancellationException from outer adapter to LF - CompletableFutureUtils.peek(ret, (v, ex) -> lf.cancel(false)); + CompletableFutureUtils.peek(ret, (v, ex) -> { + ex = CompletableFutureUtils.unwrapCfException(ex); + if (ex instanceof CancellationException) { + lf.cancel(false); + } + }); Futures.addCallback(lf, new FutureCallback() { @Override