[concurrency-interest] map over j.u.c.CompletableFuture with strict threading semantics

Viktor Klang viktor.klang at gmail.com
Fri Oct 20 10:52:43 EDT 2017


Hi Dimitar,

In general this is not possible, nor desirable, since completion is likely
to happen *before* a transformation is added.

However, there is nothing technical which prevents you to create an
implementation of CompletionStage which stores a reference to the Executor
to be used, and runs transformations which are applied to it on that
Executor unless some other Executor is specified.

-- 
Cheers,
√


On Oct 20, 2017 09:41, "Dimitar Georgiev" <dimitar.georgiev.bg at gmail.com>
wrote:

Sorry if this has already been discussed.

I need to implement the following function:

public static <A, B> CompletableFuture<B> map(CompletableFuture<A>
upstream, Function<A, B> f);

It's pretty apparent what the function does. However, it has the
requirement that f() be always executed in the thread where upstream
is completed. (That is, if upstream is completed non-exceptionally,
since if it was not, f will not be called so there is no threading
semantics concerning f)

Is this possible with j.u.c.CompletableFuture?

Regards, Dimitar
_______________________________________________
Concurrency-interest mailing list
Concurrency-interest at cs.oswego.edu
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20171020/64ef482f/attachment.html>


More information about the Concurrency-interest mailing list