Transform Java Future into a CompletableFuture

前端 未结 6 1270
野的像风
野的像风 2020-11-27 15:43

Java 8 introduces CompletableFuture, a new implementation of Future that is composable (includes a bunch of thenXxx methods). I\'d like to use this exclusively,

6条回答
  •  旧巷少年郎
    2020-11-27 16:12

    I published a little futurity project that tries to make better than the straightforward way in the answer.

    The main idea is to use the only one thread (and of course with not just a spin loop) to check all Futures states inside, which helps to avoid blocking a thread from a pool for each Future -> CompletableFuture transformation.

    Usage example:

    Future oldFuture = ...;
    CompletableFuture profit = Futurity.shift(oldFuture);
    

提交回复
热议问题