[concurrency-interest] CompletableFuture.supply

Kasper Nielsen kasperni at gmail.com
Wed Mar 11 13:02:44 EDT 2015


Hi Pavel,

This method has already been added in latest and will (most likely)  be
included in Java 9.
public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier)

see
http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/main/java/util/concurrent/CompletableFuture.java?revision=1.158&view=markup

- Kasper

On Wed, Mar 11, 2015 at 5:11 PM, Pavel Rappo <pavel.rappo at gmail.com> wrote:

> Hi, given [1] I wonder if anyone thinks this could be a useful method to be
> added to j.u.c.CompletableFuture:
>
>     public static <U> CompletableFuture<U> supply(Supplier<U> supplier)
>
> Just a completable future that is to be completed by one of those who
> claim its
> result. Right now I simulate it like this:
>
>     CompletableFuture.supply(supplier, Runnable::run)       (A)
>
> or a less flexible way [2] like this:
>
>     CompletableFuture.complete( supplier.get() )            (B)
>
> My concern is that it's not very pretty. Also it is the only method which
> missing its non-async counterpart (not that I have any kind of
> method-symmetry
> OCD, but anyway).
>
>
> -------------------------------------------------------------------------------
> [1]
> http://cs.oswego.edu/pipermail/concurrency-interest/2015-January/013600.html
> [2] In case "B" I'm starting (unconditionally and synchronously) a possibly
>     heavy computation. Which may not be needed at all (e.g.
> theAcceptEither).
> _______________________________________________
> 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/20150311/ab93ed9a/attachment.html>


More information about the Concurrency-interest mailing list