Re: CompletableFuture.cancel vs Future.cancel bug?
Sergi Vladykin via Concurrency-interest <[email protected]> Wed, 26 Aug 2020 15:34:56 +0300
| Newsgroups | gmane.comp.java.jsr.166-concurrency |
|---|---|
| Message-ID | <CA+eZwrHfKYEpAfKne95+xqtSsXq77j-fdcc167uYHN7o28U_vA@mail.gmail.com> |
> If anyone out there is implementing Future or a similar API from scratch,
> though, I wanted to at least encourage you to implement cancel(...)'s
> return value according to the current docs
>
Looks like Google guys see this spec the same way as I do.
Probably for Guava it would make sense to have an utility method in Futures
like :
public static boolean cancel(Future<?> f) {
if (f instanceof CompletableFuture)
return !f.isDone() &&
((CompletableFuture)f).completeExceptionally(new CancellationException());
else
return f.cancel(true);
}
Though, I don't see any clean workarounds for ForkJoinTask except dirty
magic with reflection/unsafe or by abusing compareAndSetForkJoinTaskTag()
method.
_______________________________________________
Concurrency-interest mailing list
[email protected]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest