[concurrency-interest] CompletableFuture exception handling

Zhong Yu zhong.j.yu at gmail.com
Wed Jun 18 17:59:30 EDT 2014


On Wed, Jun 18, 2014 at 2:09 PM, Martin Buchholz <martinrb at google.com> wrote:
> It's weird to call complete(value) in the leaf future.  Why not just
> return .... .thenAcceptBoth(...)
>
> But I haven't written "real" code using CompletableFuture myself - perhaps
> others have and can report their experience?

Yes, this should work:

    CompletableFuture<Integer> runNonblocking()
    {
        return task1(1)
            .thenCompose( i1 -> task2(i1).thenCombine(task3(i1),
(i2,i3)->i2+i3) )
            .thenCompose( i4 -> task4(i4) );
    }

PS, shameless plug, I'm working on an Async API too, in which the
example can be coded as

        Async<Integer> runNonblocking()
        {
            return task1(1)
                .then( i1 -> Async.invoke(this::plus, task2(i1), task3(i1)) )
                .then( i4 -> task4(i4) );
        }

see  http://bayou.io/release/0.9/docs/async/Async_Programming.html

Zhong Yu
http://bayou.io


More information about the Concurrency-interest mailing list