[concurrency-interest] CompletableFuture exception handling

Dennis Sosnoski dms at sosnoski.com
Wed Jun 18 21:03:35 EDT 2014


On 06/19/2014 09:59 AM, Zhong Yu wrote:
> ...
> 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) );
>      }

Wow, that's beautiful! I just needed to add a cast to 
CompletableFuture<Integer> on the thenCombine() to make the types work. 
I suppose I should have realized the key to composing and combining 
events would be in methods named "thenCompose" and "thenCombine". :-[

>
> 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

Looks interesting. I'll check into it more.

Thanks Martin and Zhong.

   - Dennis

>
> Zhong Yu
> http://bayou.io
>



More information about the Concurrency-interest mailing list