未来和 promise之间有什么区别?? 它们都像预留位置
根据 .edu / pipermail / concurrency-interest / 2012-December / 010423.html>此讨论, Promise 终于被调用 CompletableFuture 以包含在Java 8中,以及其javadoc 解释:
未来可以明确完成(设置其值和状态),并可用作完成区,支持完成后触发的依赖函数和动作。
列表中也列出了一个示例:
f.then((s - > aStringFunction).sasAsync(s - > ...);请注意,最终的API略有不同,但允许类似的异步执行:
CompletableFuture ; String> f = ...; f.thenApply(this :: modifyString).thenAccept(System.out :: println);
What's the difference between future and promise? They both act like a placeholder for future results, but where is the main difference?
解决方案According to this discussion, Promise has finally been called CompletableFuture for inclusion in Java 8, and its javadoc explains:
A Future that may be explicitly completed (setting its value and status), and may be used as a CompletionStage, supporting dependent functions and actions that trigger upon its completion.
An example is also given on the list:
f.then((s -> aStringFunction(s)).thenAsync(s -> ...);Note that the final API is slightly different but allows similar asynchronous execution:
CompletableFuture<String> f = ...; f.thenApply(this::modifyString).thenAccept(System.out::println);
更多推荐
未来与承诺的区别
发布评论