[concurrency-interest] CompletableFuture.whenComplete survey
chris.purcell.39 at gmail.com
Sat Dec 19 12:16:56 EST 2015
On Sat, 19 Dec 2015 16:40 Tim Peierls <tim at peierls.net> wrote:
> On Sat, Dec 19, 2015 at 11:16 AM, Chris Purcell <
> chris.purcell.39 at gmail.com> wrote:
>> Why not behave like a finally block, and let the user add A as a
>> suppressed exception if they want it?
> Is this opt-in behavior not achievable with a wrapper? (Assuming
> survey-option-2-without-suppression semantics.)
Yep, that's exactly what I meant, thanks for the impl!
> WhenComplete seems like the only way to reliably close resources in async
>> code, so I expected it to work like try-with-resources. That seems to be
>> the point of contention for others too. Perhaps there should be another
>> method for this use-case instead? One which takes a simple runnable and
>> suppresses any exception it throws.
> I don't see why CF.handle(BiFunction) isn't already sufficient for
> providing any behavior you want here.
In fact, the non-suppressing-option-2 whenComplete would be sufficient to
implement it. However, it's a lot of boilerplate for a common use-case, and
easy to get viciously wrong, as modifying the result of a previous stage
(even an exception) is a bug: you need to carefully clone the exception
with serialisation. I would expect there to be a default implementation
that does the obvious (painful) delegation. (And I would expect a lot of
effort to go into optimising the CompletableFuture version to avoid the
clone if it isn't needed.)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest