维基百科:在计算机科学里,future、promise和delay指的是在某些并发编程语言里用于同步的构造。它们描述一个为最初未知的结果充当代理的对象,通常因为它的值的计算还是不完整的。
术语future、promise和delay经常可交换地使用,虽然接下来将对待在future和promise之间一些用法上得不同点。具体来说,当用法有区别时,future是只读变量的占位符视图,然而promise是可写的,设置future值的单赋值容器。尤其,future可能定义为不指定具体的设置它的值的promise,和不同的合适的promises可以设置给定的future的值,尽管对于给定的future这只能做一次。在其他情况下future和promise一起创建并且彼此关联:future是值,promise是设置值 —— 本质上是一个异步函数(promise)的返回值(future)的函数。设置future的值也被称为resolving(解析)、fulfilling(实现)或者binding(绑定)它。
实现:Java通过java.util.concurrent.Future、JavaScript从ECMAScript6起等。
非标准库基于futures的实现:
- For JavaScript:
- Cujo.js's when.js provides promises conforming to the Promises/A+1.1 specification.
- The Dojo Toolkit supplies both promises and Twisted style Deferreds
- MochiKit MochKit.Async inspired by Twisted's Deferreds
- jQuery's Deferred Object is based on the CommonJS Promises/Adesign.
- Angularjs
- node-promise
- Q by Kris Kowal, conforms to Promises/A+ 1.1.
- RSVP.js also conforms to Promises/A+ 1.1.
- YUI's Promise class conforms to the Promises/A+ 1.0 specification.
- Bluebird by Petka Antonov
- See Promise/A+'s list for more implementations based on the Promise/A+ design.
- For Java: JDeferred provides Deferred/Promise API and behavior similar to JQuery.Deferred object
- For Java: Guava的com.google.common.util.concurrent.Futures
- For Java: Netty的io.netty.channel.ChannelFuture 和 io.netty.channel.ChannelPromise
暂时整理这部分,后续具体的库和详细的分析留待补充。