fbpx
维基百科

Future与promise

计算机科学中,futurepromisedelaydeferred是指用于在某些并发编程语言中同步程序执行的构造。由于某些计算(或者网络请求)尚未结束,我们需要一个对象来代理这个未知的结果,于是就有了上述这些构造(future、promise等)。

“promise”一词由丹尼尔·福瑞得曼和David Wise在1976年提出,[1] Peter Hibbard称之为“eventual”。[2] 1977年Henry Baker和Carl Hewitt在一篇论文中介绍了一个类似的概念“future”。[3]

术语“future”、“promise”、“delay”和“deferred”通常可以互换使用,而“future”与“promise”之间的使用差异,我们将在下面讨论。具体来说,当区分使用时,future是变量的“只读”占位符视图,而promise是可写的单赋值容器,用于设置future的值。 [4] 值得注意的是,无须指定可以设置其值的promise就可以定义future,并且不同的promise可以设置同一个future的值,尽管对于给定的future仅可以执行一次。在其他情况下,future和promise是一起创建的,并且相互关联:future是值,promise是设定值的函数——本质上是异步函数(promise)的返回值(future)。设置future的值的过程也称为“resolve”(解析)、“fulfil”(实现)或“bind”(绑定)它。

应用 编辑

future和promise起源于函数式编程和相关范例(如逻辑编程 ),目的是将值(future)与其计算方式(promise)分离,从而允许更灵活地进行计算,特别是通过并行化。后来,它在分布式计算中得到了应用 ,减少了通信往返的延迟。再后来,它变得更有用了,因为它允许以直接风格编写异步程序,而不是以连续传递风格英语Continuation-passing style的方式。

隐式与显式 编辑

对future的使用可能是“隐式的”(任何对future的使用都会自动获得它的值,它就像是普通的引用一样)或“显式的”(用户必须调用函数来获取值,例如Java中的Future[5]或CompletableFuture[6]get方法)。获得一个显式的future的值可以称为“stinging”或“forcing”。显式future可以作为库来实现,而隐式future则通常作为语言的一部分来实现。

最初的Baker和Hewitt论文描述了隐式future,它们在演员模型和纯面向对象编程语言(如Smalltalk)中自然得到支持。Friedman和Wise的论文只描述了显式的future,可能反映了在老旧硬件上有效实施隐式future的困难。难点在于老旧硬件不能处理原始数据类型(如整数)的future。例如,add指令不会处理3 + future factorial(100000) 。在纯演员模型或面向对象语言中,这个问题可以通过发送future factorial(100000)消息+[3],它要求future自己加3并返回结果。请注意,无论factorial(100000)何时完成计算,消息传递方法都可以工作,而且不需要任何sting或force。

promise流水线 编辑

分布式系统中使用future可以显著地减少延迟。例如,future让“promise流水线”成为了可能,[7][8] 就像在E语言和Joule语言中实现的那样,在Argus语言中这也被称为“call-stream”[9]

考虑一个涉及常规远程过程调用的表达式,例如:

 t3 := ( x.a() ).c( y.b() ) 

可以扩展为

 t1 := x.a(); t2 := y.b(); t3 := t1.c(t2); 

每个语句需要发送一条消息,并在下一个语句可以继续之前收到一个答复。例如,假设xyt1t2都位于同一台远程机器上。在这种情况下,在开始执行第三条语句之前,必须对该机器进行两次完整的网络往返。然后,第三条语句将引起另一个到同一个远程机器的往返。

使用future,上面的表达式可以写成

 t3 := (x <- a()) <- c(y <- b())

可以扩展为

 t1 := x <- a(); t2 := y <- b(); t3 := t1 <- c(t2); 

这里使用的语法是E语言的语法,其中x <- a()表示将消息a()异步发送给x。所有三个变量都会立即为其结果分配future,执行过程将继续进行到后面的语句。之后尝试解决t3的值可能会导致延迟;但是,流水线操作可以减少所需的往返次数。如果与前面的示例一样,xyt1t2都位于相同的远程机器上,则流水线实现可以用一次往返来计算t3,不必用三次。由于所有三条消息都指向同一远程计算机上的对象,因此只需要发送一个请求,只需要接收一个包含结果的响应。另请注意,即使t1t2位于不同机器上,或者位于与xy不同的机器上,发送t1 <- c(t2)也不会阻塞。

promise流水线应与并行异步消息传递区分开来。在支持并行消息传递但不支持流水线操作的系统中,上面示例中的消息发送x <- a()y <- b()可以并行进行,但发送t1 <- c(t2)将不得不等到t1t2都被接收,即使xyt1t2在同一个远程机器上。在涉及许多消息的更复杂情况下,流水线的相对延迟优势变得更大。

promise流水线操作也不应与演员系统中的流水线消息处理相混淆,在这种系统中,可以演员在完成当前消息的处理之前指定并开始执行下一个消息的行为。

只读视图 编辑

在某些编程语言(如Oz\E和AmbientTalk)中 ,可以获得未来的“只读视图”,该视图允许在resolve后读取其值,但不允许resolve它:

  • 在Oz语言中,

!!运算符用于获得只读视图

  • 在E语言和AmbientTalk中,future由一对称为“promise/resolver对”的值表示。promise表示只读视图,需要resolver来设置future的值。
  • 在C++11中,std::future提供了一个只读视图。该值通过使用std::promise直接设置,或使用std::packaged_taskstd::async设置为函数调用的结果。
  • 在Dojo Toolkit的1.5版本的Deferred API中,“仅限consumer的promise对象”表示只读视图。[10]
  • 在Alice ML中,future提供“只读视图”,而promise包含future和resolve future的能力[11][12]
  • 在.NET 4.0中,System.Threading.Tasks.Task<T>表示只读视图。解析值可以通过System.Threading.Tasks.TaskCompletionSource<T>来完成。

对只读视图的支持符合最小特权原则,因为它允许将值设置为仅限于需要设置该值的主体。在同样支持流水线的系统中,异步消息的发送方(包括结果)接收结果的只读承诺promise,消息的目标接收resolver。

针对特定线程的future 编辑

某些语言(如Alice ML )定义了与计算future值的特定线程相关联的future。[12] 这种计算可以在创建future时及早开始,或者在首次需要其值时懒惰地开始。在延迟计算的意义上,懒惰的future类似于thunk 。

Alice ML还支持可由任何线程解决的future,并调用这些“promise”。[11] “promise”的这种使用不同于上文所述的在E语言中的使用。在Alice中,promise不是只读视图,并且不支持promise流水线操作。相反,对于future未来,包括与promise相关的future,流水线是自然而然地发生的。

阻塞与非阻塞语义 编辑

如果future的值是异步访问的,例如通过向它发送消息,或者通过使用类似于E语言中的when的构造显式地等待它,那么在收到消息或完成等待之前,推迟到future得到resolve没有任何困难。这是在纯异步系统(如纯演员语言)中唯一需要考虑的情况。

然而,在某些系统中,还可能尝试“立即”或“同步”访问future的值。这样的话就需要做出一个设计选择:

  • 访问权限可能会阻塞当前线程或进程,直到future得到resolve(可能需要超时)。这是Oz语言中“数据流变量”的语义。
  • 尝试同步访问总是会发出错误信号,例如抛出异常 。这是E语言中远程promise的语义。 [13]
  • 如果future已经resolve,则访问可能成功,但如果未resolve,则发出错误信号。这样做的缺点是引入了不确定性和潜在的竞争条件,这似乎是一种不常见的设计选择。

作为第一种可能性的示例,在C++11中 ,需要future值的线程可以通过调用wait()get()成员函数来阻塞,直到可用为止。您还可以使用wait_for()wait_until()成员函数指定等待超时,以避免无限期阻塞。如果future对std::async的调用,那么阻塞等待(没有超时)可能导致函数的同步调用以计算等待线程上的结果。

相关结构 编辑

“future”是Event(同步原语)的特例,只能完成一次。通常,event可以重置为初始空状态,因此可以根据需要多次完成。[14]

“I-var”(如在语言Id中)是具有上面定义的阻塞语义的future。“I-structure”是包含I-var的数据结构。可以使用不同值多次设置的相关同步构造称为“M-var”。M-var支持“采用”或“放置”当前值的原子操作,其中取值还将M-var设置回其初始“空”状态。 [15]

“并发逻辑变量”与future类似,但是通过合一更新,与逻辑编程中的“逻辑变量”相同。因此,它可以多次绑定到可合一的值,但不能设置回空或unresolved状态。Oz的数据流变量充当并发逻辑变量,并且还具有上面提到的阻塞语义。

“并发约束变量”是并发逻辑变量的一般化,以支持约束逻辑编程:约束可以多次“缩小”,表示可能值的较小集合。通常,有一种方法可以指定每当约束进一步缩小时应该运行的hunk;这是支持“约束传播”所必需的。

不同形式future的表达能力之间的关系 编辑

通过在创建future的同时创建一个计算值的线程,可以在非线程特有的promise中直接实现及早求值的线程特有的future。在这种情况下,future将只读视图返回给客户端,以便仅让新创建的线程能够解决这个future。


要在非线程特有的promise中实现隐式延迟线程特有的promise(比如由Alice ML提供),需要一种机制来确定何时首先需要future的值(例如,Oz中的WaitNeeded构造[16] )。 如果所有值都是对象,那么实现透明转发对象的能力就足够了,因为发送给转发器的第一条消息表明需要future的值。

假定系统支持消息传递,通过让resolve线程向future自己的线程发送消息,可以在线程特有的future中实现非线程特有的future。但是,这可以被视为不必要的复杂性。在基于线程的编程语言中,最具表现力的方法似乎是提供非线程特有的future,只读视图以及“WaitNeeded”构造或支持透明转发的混合。

求值策略 编辑

future的求值策略(可称为“传future调用”)是非确定性的:future的值将在创建future和使用其值之间的某个时间进行求值,但确切的时间不确定的,一次运行和另一次运行的求值时间会不一样。计算可以在创建future时开始(及早求值),或者仅在实际需要值时开始(懒惰求值),并且可以在中途暂停,或在一次运行中执行。一旦future被赋值,它就不会在访问future的时候重新计算;这就像传需求调用时使用的记忆化

懒惰future是确定性具有惰性求值评估语义的future:future值的计算在首次需要时开始,与传需要调用一样。懒惰future在求值策略默认不是懒惰求值的语言中使用。例如,在C++11中,可以通过将std::launch::deferred启动策略传递给std::async以及计算值的函数来创建这种惰性future。

演员模型中的future语义 编辑

在演员模型中,形式为future <Expression>的表达式由它对Eval消息(环境为E,客户为C)的响应方式定义:future表达式通过向客户C发送新创建的演员来响应Eval消息F(计算<Expression>的响应的代理)作为返回值,“与此同时"向<Expression>发送环境E和客户C的Eval消息。F的默认行为如下:

  • 当F收到请求R时,它会通过评估<Expression>继续检查它是否已收到响应(可以是返回值或抛出异常),如下所示:
    1. 如果它已经有响应V,那么
      • 如果V是返回值,则发送给请求R.
      • 如果V是一个异常,那么就会把这个异常抛给请求R的客户。
    2. 如果它还没有响应,则R存储在F内的请求队列中。
  • 当F从评估<Expression>接到响应V时,则V存储在F中
    • 如果V是返回值,则将V发送到所有排队的请求.
    • 如果V是一个异常,那么就会把这个异常抛出给每个排队请求的客户。

但是,一些future可以通过特殊方式处理请求以提供更大的并行性。例如,表达式1 + future factorial(n)可以创建一个新的future,其行为类似于数字1+factorial(n) 。这个技巧并不总是有效。例如,以下条件表达式:

if m>future factorial(n) then print("bigger") else print("smaller")

挂起,直到factorial(n)这个future已回应询问m是否大于其自身的请求。

历史 编辑

“future”与“promise”构造首先在诸如MultiLisp和Act 1之类的编程语言中实现。在并发逻辑编程语言中使用逻辑变量进行通信非常类似于future。这些开始于“Prolog with Freeze”和“IC Prolog”,并成为真正的并发原语,包括关系语言、Concurrent Prolog、守卫霍恩子句(GHC)、Parlog、Strand、Vulcan、Janus、Oz-Mozart、Flow Java和Alice ML。来自数据流编程语言的单一赋值“I-var”,源自Id并包含在Reppy的“Concurrent ML”中,非常类似于并发逻辑变量。

promise流水线技术(使用future来克服延迟)是Barbara Liskov和Liuba Shrira于1988年发明的[9],由Mark S. Miller、Dean Tribble和Rob Jellinghaus在大约1989年的Xanadu项目中独立发明。[17]

“promise”一词是由Liskov和Shrira创造的,尽管他们通过名称“call-stream”引用了流水线机制,现在很少使用它。

Liskov和Shrira的论文中描述的设计以及Xanadu中的promise流水线的实现都有一个限制,即promise值不是一等的:一个参数,或者一个call或send返回的值不能直接成为一个promise (所以前面给出的promise流水线的例子,它使用一个发送的结果作为另一个发送的参数的承诺,在call-stream设计或Xanadu实现中不能直接表达)。似乎promise和call-stream从未在Argus的任何公开发布中实现, [18] Liskov和Shrira论文中使用的编程语言。Argus的开发在1988年左右停止了。[19] Xanadu实现的promise流水线仅在1999年Udanax Gold[20]的源代码发布时才公开发布,并且在任何已发布的文档中都没有解释过。[21] Joule和E的后续实现支持完全一等的promise和resolver。

一些早期的演员语言,包括Act系列,[22][23] 支持并行消息传递和流水线消息处理,但不支持promise流水线。(虽然技术上可以在前两个中实现最后一个功能,但没有证据表明Act语言这样做了。)

2000年之后,由于消息传递的请求-响应模型,future和promise在用户界面响应和web开发中的应用重新引起了人们的兴趣。现在有几种主流语言对future和promise都有语言支持,最着名的是Java 5中的FutureTask(2004年公布)[24]以及.NET 4.5中的asyncawait结构(2010年发布,2012年发布)[25][26]很大程度上受到F#的“异步工作流程”(可追溯到2007年[27])的启发[28]。 随后被其他语言采用,特别是Dart(2014)[29],Python(2015)[30], Hack(HHVM)以及ECMAScript 7(JavaScript)、Scala和C++的草案。

实现列表 编辑

支持future、promise、并发逻辑变量、数据流变量或I-vars的语言,无论是通过直接语言支持还是在标准库中,包括:

  • FreeFuture 通过FreeFuture[31]
  • ABCL/f[32]
  • Alice ML
  • AmbientTalk(包含一流的解析器和只读promise)
  • C ++,从C++11开始:std::future和std::promise
    • μC++
    • Compositional C++
  • Crystal语言
  • Dart(使用Future/Completer类[33]以及关键字await和async[29]
  • Elm语言通过Task模块[34]
  • Glasgow Haskell (仅限I-vars和M-vars)
  • Id (仅限I-vars和M-vars)
  • Io[35]
  • Java通过Future[5]或CompletableFuture[6]
    • Flow Java
  • JavaScript(有限,从ECMAScript 6起支持)
  • Lucid(仅限数据流)
  • 一些Lisp
  • .NET通过Tasks
    • C#,自.NET 4.5起,[25]通过关键字asyncawait[26]
  • Nim
  • Oxygene
  • Oz版本3 [37]
  • Perl 6[38]
  • Python concurrent.futures[39], 自从版本3.2,[40] 由PEP 3148所提议[41], 而Python 3.5增加了async和await[42]
  • R(延迟计算的promise,仍然是单线程)
  • Racket[43]
  • Scala通过scala.concurrent包[44]
  • Scheme
  • Squeak Smalltalk
  • Strand
  • Swift (仅通过第三方库)
  • Visual Basic 11(通过关键字Async和Await)[26]

还支持promise流水线的语言包括:

  • E
  • Joule

基于非标准库的future实现:

  • 对于Common Lisp
  • 对于C++:
  • 对于C#和其他.NET语言:Parallel Extensions库
  • 对于Groovy:GPars[55]
  • 对于JavaScript
    • Cujo.js'[56] when.js[57]提供符合Promises/A+[58] 1.1规范的promise
    • Dojo Toolkit提供promises[59]和Twisted方式延迟
    • MochiKit [60]受Twisted's Deferreds的启发
    • jQuery[61]的Deferred Object[62]基于CommonJS Promises/A[63]设计。
    • Angularjs[64]
    • node-promise[65]
    • Q,作者为Kris Kowal,符合Promises/A+ 1.1[66]
    • RSVP.js,符合Promises/A+ 1.1[67]
    • YUI的[68]promise类[69]符合Promises/A+ 1.0规范。
    • Bluebird,作者Petka Antonov[70]
    • Closure Library的promise[71]包符合Promises/A+规范。
    • 有关基于Promise/A+设计的更多实现,请参阅Promise/A+[72]列表。
  • 对于Java
    • JDeferred提供了与JQuery类似的deferred-promise API和行为。Deferred对象[73]
    • ParSeq[74]提供task-promise API,由LinkedIn维护,适用于异步流水线和分支
  • 对于Objective-C:MAFuture[75][76]、RXPromise[77]、ObjC-CollapsingFutures[78]、PromiseKit[79]、objc-promise[80]、OAPromise[81]
  • 对于OCaml:Lazy模块实现了懒惰的显式期货[82]
  • 对于Perl:Future[83]、Promises[84]、和Reflex[85]
  • 对于PHP:React/Promise [86]
  • 对于Python
  • 对于R
    • future,实现可扩展的future API与懒惰和及早同步和(多核或分布式)异步期货[90] [90]
  • 对于Ruby
    • Promise gem[91]
    • libuv gem,实现promise[92]
    • Celluloid gem,实现future[93]
    • future-resource[94]
  • 对于Rust:
  • 对于Scala
    • Twitter的util库[96]
  • 对于Swift:
    • 异步框架,实现C#风格的async/非阻塞await[97]
    • FutureKit[98]、实现了Apple GCD的版本[99]
    • FutureLib,纯Swift 2库实现的Scala风格的future和promise与TPL风格的取消[100]
    • Deferred,纯Swift库,受到OCaml的Deferred启发[101]
    • BrightFutures[102]
  • 对于Tcl:tcl-promise[103]

协程 编辑

future可以用协程[30]或生成器实现,[104] 从而产生相同的评估策略(例如,协同多任务或延迟评估)。

通道 编辑

future可以很容易地用通道实现:future是一个单元素的通道,而promise是一个发送到通道,实现future的过程。 [105] [106] 这允许future在支持通道(如CSP和Go)的并发编程语言中实现。由此产生的future是显式的,因为它们必须通过从通道读取而不是仅仅通过评估来获取。

参见 编辑

参考资料 编辑

  1. ^ Friedman, Daniel; David Wise. The Impact of Applicative Programming on Multiprocessing. International Conference on Parallel Processing: 263–272. 1976. 
  2. ^ Hibbard, Peter. Parallel Processing Facilities. New Directions in Algorithmic Languages, (ed.) Stephen A. Schuman, IRIA, 1976. 1976. 
  3. ^ Henry Baker; Carl Hewitt. . Proceedings of the Symposium on Artificial Intelligence Programming Languages,. ACM Sigplan Notices 12, 8: 55–59. August 1977 [2018-12-31]. (原始内容存档于2008-07-04). 
  4. ^ "SIP-14 – Futures and Promises (页面存档备份,存于互联网档案馆)"
  5. ^ 5.0 5.1 java.util.concurrent.Future
  6. ^ 6.0 6.1 java.util.concurrent.CompletableFuture
  7. ^ Promise Pipelining. www.erights.org. [2018-12-31]. (原始内容于2018-10-22). 
  8. ^ Promise Pipelining on the C2 wiki. [2018-12-31]. (原始内容于2005-09-25). 
  9. ^ 9.0 9.1 Barbara Liskov; Liuba Shrira. Promises: Linguistic Support for Efficient Asynchronous Procedure Calls in Distributed Systems. Proceedings of the SIGPLAN '88 Conference on Programming Language Design and Implementation; Atlanta, Georgia, United States. ACM: 260–267. 1988. ISBN 0-89791-269-1. doi:10.1145/53990.54016.  Also published in ACM SIGPLAN Notices 23(7).
  10. ^ Robust promises with Dojo deferred, Site Pen, 2010-05-03 [2018-12-31], (原始内容于2018-12-31) 
  11. ^ 11.0 11.1 Promise, , DE: Uni-SB, [2018-12-31], (原始内容存档于2008-10-08) 
  12. ^ 12.0 12.1 Future, , DE: Uni-SB, [2018-12-31], (原始内容存档于2008-10-06) 
  13. ^ Promise, E rights, [2018-12-31], (原始内容于2018-12-31) 
  14. ^ 500 lines or less, "A Web Crawler With asyncio Coroutines" by A. Jesse Jiryu Davis and Guido van Rossum (页面存档备份,存于互联网档案馆) says "implementation uses an asyncio.Event in place of the Future shown here. The difference is an Event can be reset, whereas a Future cannot transition from resolved back to pending."
  15. ^ , Haskell, [2018-12-31], (原始内容存档于2009-04-18) 
  16. ^ , Mozart Oz, [2018-12-31], (原始内容存档于2013-05-17) 
  17. ^ , Sunless Sea, [2018-12-31], (原始内容存档于2007-10-23) 
  18. ^ Argus, MIT, [2018-12-31], (原始内容于2018-04-27) 
  19. ^ Liskov, Barbara, Distributed computing and Argus, Oral history, IEEE GHN, [2018-12-31], (原始内容于2014-11-22) 
  20. ^ , Udanax, [2018-12-31], (原始内容存档于2008-10-11) 
  21. ^ Pipeline, E rights, [2018-12-31], (原始内容于2018-10-22) 
  22. ^ Henry Lieberman. A Preview of Act 1. MIT AI memo 625. June 1981. 
  23. ^ Henry Lieberman. Thinking About Lots of Things at Once without Getting Confused: Parallelism in Act 1. MIT AI memo 626. June 1981. 
  24. ^ Goetz, Brian. Concurrency in JDK 5.0. 2004-11-23. (原始内容于2018-11-13). 
  25. ^ 25.0 25.1 Async in 4.5: Worth the Await – .NET Blog – Site Home – MSDN Blogs. Blogs.msdn.com. [2014-05-13]. (原始内容于2012-04-07). 
  26. ^ 26.0 26.1 26.2 Asynchronous Programming with Async and Await (C# and Visual Basic). Msdn.microsoft.com. [2014-05-13]. (原始内容于2014-05-27). 
  27. ^ Don Syme; Tomas Petricek; Dmitry Lomov. The F# Asynchronous Programming Model, PADL 2011. 2010-10-21 [2018-12-31]. (原始内容于2015-05-15). 
  28. ^ Tomas Petricek. Asynchronous C# and F# (I.): Simultaneous introduction. 2010-10-29 [2018-12-31]. (原始内容于2018-12-31). 
  29. ^ 29.0 29.1 Gilad Bracha. Dart Language Asynchrony Support: Phase 1. October 2014 [2018-12-31]. (原始内容于2016-07-02). 
  30. ^ 30.0 30.1 PEP 0492 – Coroutines with async and await syntax. [2018-12-31]. (原始内容于2019-01-05). 
  31. ^ FreeFuture(页面存档备份,存于互联网档案馆
  32. ^ Kenjiro Taura; Satoshi Matsuoka; Akinori Yonezawa. ABCL/f: A Future-Based Polymorphic Typed Concurrent Object-Oriented Language – Its Design and Implementation.. In Proceedings of the DIMACS workshop on Specification of Parallel Algorithms, number 18 in Dimacs Series in Discrete Mathematics and Theoretical Computer Science. American Mathematical Society: 275–292. 1994. CiteSeerX 10.1.1.23.1161 . 
  33. ^ Dart SDK dart async Completer. [2018-12-31]. (原始内容于2016-03-04). 
  34. ^ Task. [2018-12-31]. (原始内容于2018-12-31). 
  35. ^ Steve Dekorte. Io, The Programming Language. 2005 [2018-12-31]. (原始内容于2019-01-04). 
  36. ^ Rich Hickey. changes.txt at 1.1.x from richhickey's clojure. 2009 [2018-12-31]. (原始内容于2016-02-18). 
  37. ^ Seif Haridi; Nils Franzen. . Mozart Global User Library. [2011-04-12]. (原始内容存档于2011-05-14). 
  38. ^ Perl 6中的Promise类. docs.perl6.org. [2019-01-04]. (原始内容于2018-12-31). 
  39. ^ concurrent.futures(页面存档备份,存于互联网档案馆
  40. ^ Python 3.2 发布. Python.org. [2018-12-31]. (原始内容于2018-12-31). 
  41. ^ PEP 3148(页面存档备份,存于互联网档案馆
  42. ^ Python 3.5.0 发布. Python.org. [2018-12-31]. (原始内容于2019-01-05). 
  43. ^ Parallelism with Futures. PLT. [2012-03-02]. (原始内容于2012-03-23). 
  44. ^ scala.concurrent包(页面存档备份,存于互联网档案馆
  45. ^ Blackbird promise library - Blackbird. orthecreedence.github.io. [2018-12-31]. (原始内容于2017-11-10). 
  46. ^ Eager Future2. common-lisp.net. [2019-01-04]. (原始内容于2018-12-31). 
  47. ^ - Common Lisp的并行编程库[永久失效連結]
  48. ^ PCall. marijnhaverbeke.nl. [2018-12-31]. (原始内容于2020-08-06). 
  49. ^ Chapter 30. Thread 4.0.0. [2013-06-26]. (原始内容于2019-10-16). 
  50. ^ Dlib C++ Library #thread_pool. [2013-06-26]. (原始内容于2019-10-16). 
  51. ^ . Qt Project. [2013-06-26]. (原始内容存档于2013-06-01). 
  52. ^ Seastar. Seastar project. [2016-08-22]. (原始内容于2016-08-20). 
  53. ^ GitHub – facebook/folly: An open-source C++ library developed and used at Facebook.. [2018-12-31]. (原始内容于2019-03-22). 
  54. ^ Threads Slides of POCO (PDF). [2018-12-31]. (原始内容 (PDF)于2020-05-08). 
  55. ^ . [2018-12-31]. (原始内容存档于2013-01-12). 
  56. ^ cujoJS: Javascript architectural toolkit. cujojs.com. [2019-01-04]. (原始内容于2012-03-17). 
  57. ^ A solid, fast Promises/A+ and when() implementation, plus other async goodies.: cujojs/when. 2018-12-25 [2018-12-31]. (原始内容于2019-01-16) –通过GitHub. 
  58. ^ Promises/A+. promisesaplus.com. [2019-01-04]. (原始内容于2018-12-29). 
  59. ^ Dojo Deferreds and Promises - Archived Tutorial - Dojo Toolkit. dojotoolkit.org. [2019-01-04]. (原始内容于2018-12-31). 
  60. ^ manage asynchronous tasks. MochiKit.Async. [2019-01-04]. (原始内容于2018-12-31). 
  61. ^ jQuery. [2018-12-31]. (原始内容存档于2012-02-29). 
  62. ^ 存档副本. [2018-12-31]. (原始内容存档于2012-02-29).  Deferred Object
  63. ^ CommonJS Promises/A(页面存档备份,存于互联网档案馆
  64. ^ AngularJS — Superheroic JavaScript MVW Framework. angularjs.org. [2019-01-04]. (原始内容于2015-06-23). 
  65. ^ Promise utilities for Node. Contribute to kriszyp/node-promise development by creating an account on GitHub. 2018-10-22 [2018-12-31]. (原始内容于2019-05-27) –通过GitHub. 
  66. ^ kriskowal/q. documentup.com. [2018-12-31]. (原始内容于2018-12-31). 
  67. ^ A lightweight library that provides tools for organizing asynchronous code: tildeio/rsvp.js. 2019-01-03 [2018-12-31]. (原始内容于2019-01-17) –通过GitHub. 
  68. ^ YUI Javascript 类库. yuilibrary.com. [2019-01-04]. (原始内容于2019-01-12). 
  69. ^ Promise - YUI Library. yuilibrary.com. [2019-01-04]. (原始内容于2018-12-31). 
  70. ^ :bird: :zap: Bluebird is a full featured promise library with unmatched performance.: petkaantonov/bluebird. 2019-01-04 [2018-12-31]. (原始内容于2018-12-28) –通过GitHub. 
  71. ^ promise(页面存档备份,存于互联网档案馆
  72. ^ Promise/A+(页面存档备份,存于互联网档案馆
  73. ^ JDeferred. JDeferred. [2019-01-04]. (原始内容于2019-01-08). 
  74. ^ Asynchronous Java made easier. Contribute to linkedin/parseq development by creating an account on GitHub. 2018-12-29 [2018-12-31]. (原始内容于2018-06-10) –通过GitHub. 
  75. ^ Proxying futures library for Objective-C. Contribute to mikeash/MAFuture development by creating an account on GitHub. 2019-01-01 [2018-12-31]. (原始内容于2019-02-13) –通过GitHub. 
  76. ^ mikeash.com: Friday Q&A 2010-02-26: Futures. www.mikeash.com. [2019-01-04]. (原始内容于2018-12-31). 
  77. ^ An Objective-C Class which implements the Promises/A+ specification.: couchdeveloper/RXPromise. 2018-12-26 [2018-12-31]. (原始内容于2018-06-11) –通过GitHub. 
  78. ^ Futures, for Objective-C, that automatically collapse so it's nearly impossible to mix up the level of future nesting despite the lack of generics.: Strilanc/ObjC-CollapsingFutures. 2018-12-07 [2018-12-31]. (原始内容于2018-06-11) –通过GitHub. 
  79. ^ Promises for Swift & ObjC. Contribute to mxcl/PromiseKit development by creating an account on GitHub. 2019-01-03 [2019-01-04]. (原始内容于2019-01-08) –通过GitHub. 
  80. ^ Objective-C Promises in the CommonJS style. Contribute to mproberts/objc-promise development by creating an account on GitHub. 2018-09-11 [2018-12-31]. (原始内容于2018-06-11) –通过GitHub. 
  81. ^ OAPromise is an API separating async operations and their callbacks, adding consistency and useful features like fall-through errors and progress reports.: oleganza/OAPromise. 2017-03-29 [2018-12-31]. (原始内容于2013-10-27) –通过GitHub. 
  82. ^ Lazy. caml.inria.fr. [2018-12-31]. (原始内容存档于2015-07-06). 
  83. ^ Future - represent an operation awaiting completion - metacpan.org. metacpan.org. [2019-01-04]. (原始内容于2019-01-01). 
  84. ^ Promises - An implementation of Promises in Perl - metacpan.org. metacpan.org. [2018-12-31]. (原始内容于2018-12-31). 
  85. ^ Reflex - Class library for flexible, reactive programs. - metacpan.org. metacpan.org. [2019-01-04]. (原始内容于2019-01-04). 
  86. ^ Promises/A implementation for PHP. Contribute to reactphp/promise development by creating an account on GitHub. 2019-01-04 [2018-12-31]. (原始内容于2019-04-07) –通过GitHub. 
  87. ^ Coroutines and Tasks — Python 3.7.2 documentation. docs.python.org. [2018-12-31]. (原始内容于2018-12-31). 
  88. ^ Google Code Archive - Long-term storage for Google Code Project Hosting.. code.google.com. [2019-01-04]. (原始内容于2020-08-06). 
  89. ^ Deferred Reference — Twisted 18.9.0 documentation. twistedmatrix.com. [2019-01-04]. (原始内容于2018-12-31). 
  90. ^ 90.0 90.1 Bengtsson, Henrik. future: Unified Parallel and Distributed Processing in R for Everyone. 2018-10-17 [2018-12-31]. (原始内容于2019-10-16) –通过R-Packages. 
  91. ^ promise - RubyGems.org - your community gem host. rubygems.org. [2019-01-04]. (原始内容于2018-12-31). 
  92. ^ Ruby bindings for libuv. Contribute to cotag/libuv development by creating an account on GitHub. 2018-10-16 [2018-12-31]. (原始内容于2018-06-11) –通过GitHub. 
  93. ^ . celluloid.io. [2019-01-04]. (原始内容存档于2018-12-31). 
  94. ^ Wait on resources being set in the future. Contribute to adhearsion/future-resource development by creating an account on GitHub. 2013-12-27 [2018-12-31]. (原始内容于2018-06-11) –通过GitHub. 
  95. ^ Zero-cost asynchronous programming in Rust. Contribute to rust-lang-nursery/futures-rs development by creating an account on GitHub. 2019-01-04 [2019-01-04]. (原始内容于2019-02-26) –通过GitHub. 
  96. ^ Util. twitter.github.io. [2018-12-31]. (原始内容于2018-12-23). 
  97. ^ al45tair / Async. bitbucket.org. [2018-12-31]. (原始内容于2018-12-31). 
  98. ^ A Swift based Future/Promises Library for IOS and OS X.: FutureKit/FutureKit. 2018-12-31 [2018-12-31]. (原始内容于2018-08-10) –通过GitHub. 
  99. ^ Dispatch - Apple Developer Documentation. developer.apple.com. [2019-01-04]. (原始内容于2018-12-31). 
  100. ^ FutureLib is a pure Swift 2 library implementing Futures & Promises inspired by Scala.: couchdeveloper/FutureLib. 2018-10-15 [2018-12-31]. (原始内容于2018-06-12) –通过GitHub. 
  101. ^ Work with values that haven't been determined yet.: bignerdranch/Deferred. 2019-01-02 [2019-01-04]. (原始内容于2018-06-10) –通过GitHub. 
  102. ^ Write great asynchronous code in Swift using futures and promises: Thomvis/BrightFutures. 2019-01-03 [2018-12-31]. (原始内容于2018-06-11) –通过GitHub. 
  103. ^ tcl-promise. SourceForge. [2018-12-31]. (原始内容于2018-12-31). 
  104. ^ Does async/await solve a real problem?. esdiscuss.org. [2018-12-31]. (原始内容于2018-11-13). 
  105. ^ Futures - Go Language Patterns. www.golangpatterns.info. [2019-01-04]. (原始内容于2019-01-04). 
  106. ^ Go Language Patterns. www.golangpatterns.info. [2019-01-04]. (原始内容于2019-01-04). 

外部链接 编辑

future与promise, 在计算机科学中, future, promise, delay和deferred是指用于在某些并发编程语言中同步程序执行的构造, 由于某些计算, 或者网络请求, 尚未结束, 我们需要一个对象来代理这个未知的结果, 于是就有了上述这些构造, future, promise等, promise, 一词由丹尼尔, 福瑞得曼和david, wise在1976年提出, peter, hibbard称之为, eventual, 1977年henry, baker和carl, hewitt在一篇论. 在计算机科学中 future promise delay和deferred是指用于在某些并发编程语言中同步程序执行的构造 由于某些计算 或者网络请求 尚未结束 我们需要一个对象来代理这个未知的结果 于是就有了上述这些构造 future promise等 promise 一词由丹尼尔 福瑞得曼和David Wise在1976年提出 1 Peter Hibbard称之为 eventual 2 1977年Henry Baker和Carl Hewitt在一篇论文中介绍了一个类似的概念 future 3 术语 future promise delay 和 deferred 通常可以互换使用 而 future 与 promise 之间的使用差异 我们将在下面讨论 具体来说 当区分使用时 future是变量的 只读 占位符视图 而promise是可写的单赋值容器 用于设置future的值 4 值得注意的是 无须指定可以设置其值的promise就可以定义future 并且不同的promise可以设置同一个future的值 尽管对于给定的future仅可以执行一次 在其他情况下 future和promise是一起创建的 并且相互关联 future是值 promise是设定值的函数 本质上是异步函数 promise 的返回值 future 设置future的值的过程也称为 resolve 解析 fulfil 实现 或 bind 绑定 它 目录 1 应用 2 隐式与显式 3 promise流水线 4 只读视图 5 针对特定线程的future 6 阻塞与非阻塞语义 7 相关结构 8 不同形式future的表达能力之间的关系 9 求值策略 10 演员模型中的future语义 11 历史 12 实现列表 12 1 协程 12 2 通道 13 参见 14 参考资料 15 外部链接应用 编辑future和promise起源于函数式编程和相关范例 如逻辑编程 目的是将值 future 与其计算方式 promise 分离 从而允许更灵活地进行计算 特别是通过并行化 后来 它在分布式计算中得到了应用 减少了通信往返的延迟 再后来 它变得更有用了 因为它允许以直接风格编写异步程序 而不是以连续传递风格 英语 Continuation passing style 的方式 隐式与显式 编辑对future的使用可能是 隐式的 任何对future的使用都会自动获得它的值 它就像是普通的引用一样 或 显式的 用户必须调用函数来获取值 例如Java中的Future 5 或CompletableFuture 6 的get方法 获得一个显式的future的值可以称为 stinging 或 forcing 显式future可以作为库来实现 而隐式future则通常作为语言的一部分来实现 最初的Baker和Hewitt论文描述了隐式future 它们在演员模型和纯面向对象编程语言 如Smalltalk 中自然得到支持 Friedman和Wise的论文只描述了显式的future 可能反映了在老旧硬件上有效实施隐式future的困难 难点在于老旧硬件不能处理原始数据类型 如整数 的future 例如 add指令不会处理3 future factorial 100000 在纯演员模型或面向对象语言中 这个问题可以通过发送future factorial 100000 消息 3 它要求future自己加3并返回结果 请注意 无论factorial 100000 何时完成计算 消息传递方法都可以工作 而且不需要任何sting或force promise流水线 编辑在分布式系统中使用future可以显著地减少延迟 例如 future让 promise流水线 成为了可能 7 8 就像在E语言和Joule语言中实现的那样 在Argus语言中这也被称为 call stream 9 考虑一个涉及常规远程过程调用的表达式 例如 t3 x a c y b 可以扩展为 t1 x a t2 y b t3 t1 c t2 每个语句需要发送一条消息 并在下一个语句可以继续之前收到一个答复 例如 假设x y t1和t2都位于同一台远程机器上 在这种情况下 在开始执行第三条语句之前 必须对该机器进行两次完整的网络往返 然后 第三条语句将引起另一个到同一个远程机器的往返 使用future 上面的表达式可以写成 t3 x lt a lt c y lt b 可以扩展为 t1 x lt a t2 y lt b t3 t1 lt c t2 这里使用的语法是E语言的语法 其中x lt a 表示将消息a 异步发送给x 所有三个变量都会立即为其结果分配future 执行过程将继续进行到后面的语句 之后尝试解决t3的值可能会导致延迟 但是 流水线操作可以减少所需的往返次数 如果与前面的示例一样 x y t1和t2都位于相同的远程机器上 则流水线实现可以用一次往返来计算t3 不必用三次 由于所有三条消息都指向同一远程计算机上的对象 因此只需要发送一个请求 只需要接收一个包含结果的响应 另请注意 即使t1和t2位于不同机器上 或者位于与x或y不同的机器上 发送t1 lt c t2 也不会阻塞 promise流水线应与并行异步消息传递区分开来 在支持并行消息传递但不支持流水线操作的系统中 上面示例中的消息发送x lt a 和y lt b 可以并行进行 但发送t1 lt c t2 将不得不等到t1和t2都被接收 即使x y t1和t2在同一个远程机器上 在涉及许多消息的更复杂情况下 流水线的相对延迟优势变得更大 promise流水线操作也不应与演员系统中的流水线消息处理相混淆 在这种系统中 可以演员在完成当前消息的处理之前指定并开始执行下一个消息的行为 只读视图 编辑在某些编程语言 如Oz E和AmbientTalk 中 可以获得未来的 只读视图 该视图允许在resolve后读取其值 但不允许resolve它 在Oz语言中 运算符用于获得只读视图 在E语言和AmbientTalk中 future由一对称为 promise resolver对 的值表示 promise表示只读视图 需要resolver来设置future的值 在C 11中 std future提供了一个只读视图 该值通过使用std promise直接设置 或使用std packaged task或std async设置为函数调用的结果 在Dojo Toolkit的1 5版本的Deferred API中 仅限consumer的promise对象 表示只读视图 10 在Alice ML中 future提供 只读视图 而promise包含future和resolve future的能力 11 12 在 NET 4 0中 System Threading Tasks Task lt T gt 表示只读视图 解析值可以通过System Threading Tasks TaskCompletionSource lt T gt 来完成 对只读视图的支持符合最小特权原则 因为它允许将值设置为仅限于需要设置该值的主体 在同样支持流水线的系统中 异步消息的发送方 包括结果 接收结果的只读承诺promise 消息的目标接收resolver 针对特定线程的future 编辑某些语言 如Alice ML 定义了与计算future值的特定线程相关联的future 12 这种计算可以在创建future时及早开始 或者在首次需要其值时懒惰地开始 在延迟计算的意义上 懒惰的future类似于thunk Alice ML还支持可由任何线程解决的future 并调用这些 promise 11 promise 的这种使用不同于上文所述的在E语言中的使用 在Alice中 promise不是只读视图 并且不支持promise流水线操作 相反 对于future未来 包括与promise相关的future 流水线是自然而然地发生的 阻塞与非阻塞语义 编辑如果future的值是异步访问的 例如通过向它发送消息 或者通过使用类似于E语言中的when的构造显式地等待它 那么在收到消息或完成等待之前 推迟到future得到resolve没有任何困难 这是在纯异步系统 如纯演员语言 中唯一需要考虑的情况 然而 在某些系统中 还可能尝试 立即 或 同步 访问future的值 这样的话就需要做出一个设计选择 访问权限可能会阻塞当前线程或进程 直到future得到resolve 可能需要超时 这是Oz语言中 数据流变量 的语义 尝试同步访问总是会发出错误信号 例如抛出异常 这是E语言中远程promise的语义 13 如果future已经resolve 则访问可能成功 但如果未resolve 则发出错误信号 这样做的缺点是引入了不确定性和潜在的竞争条件 这似乎是一种不常见的设计选择 作为第一种可能性的示例 在C 11中 需要future值的线程可以通过调用wait 或get 成员函数来阻塞 直到可用为止 您还可以使用wait for 或wait until 成员函数指定等待超时 以避免无限期阻塞 如果future对std async的调用 那么阻塞等待 没有超时 可能导致函数的同步调用以计算等待线程上的结果 相关结构 编辑 future 是Event 同步原语 的特例 只能完成一次 通常 event可以重置为初始空状态 因此可以根据需要多次完成 14 I var 如在语言Id中 是具有上面定义的阻塞语义的future I structure 是包含I var的数据结构 可以使用不同值多次设置的相关同步构造称为 M var M var支持 采用 或 放置 当前值的原子操作 其中取值还将M var设置回其初始 空 状态 15 并发逻辑变量 与future类似 但是通过合一更新 与逻辑编程中的 逻辑变量 相同 因此 它可以多次绑定到可合一的值 但不能设置回空或unresolved状态 Oz的数据流变量充当并发逻辑变量 并且还具有上面提到的阻塞语义 并发约束变量 是并发逻辑变量的一般化 以支持约束逻辑编程 约束可以多次 缩小 表示可能值的较小集合 通常 有一种方法可以指定每当约束进一步缩小时应该运行的hunk 这是支持 约束传播 所必需的 不同形式future的表达能力之间的关系 编辑通过在创建future的同时创建一个计算值的线程 可以在非线程特有的promise中直接实现及早求值的线程特有的future 在这种情况下 future将只读视图返回给客户端 以便仅让新创建的线程能够解决这个future 要在非线程特有的promise中实现隐式延迟线程特有的promise 比如由Alice ML提供 需要一种机制来确定何时首先需要future的值 例如 Oz中的WaitNeeded构造 16 如果所有值都是对象 那么实现透明转发对象的能力就足够了 因为发送给转发器的第一条消息表明需要future的值 假定系统支持消息传递 通过让resolve线程向future自己的线程发送消息 可以在线程特有的future中实现非线程特有的future 但是 这可以被视为不必要的复杂性 在基于线程的编程语言中 最具表现力的方法似乎是提供非线程特有的future 只读视图以及 WaitNeeded 构造或支持透明转发的混合 求值策略 编辑更多信息 求值策略 future的求值策略 可称为 传future调用 是非确定性的 future的值将在创建future和使用其值之间的某个时间进行求值 但确切的时间不确定的 一次运行和另一次运行的求值时间会不一样 计算可以在创建future时开始 及早求值 或者仅在实际需要值时开始 懒惰求值 并且可以在中途暂停 或在一次运行中执行 一旦future被赋值 它就不会在访问future的时候重新计算 这就像传需求调用时使用的记忆化 懒惰future是确定性具有惰性求值评估语义的future future值的计算在首次需要时开始 与传需要调用一样 懒惰future在求值策略默认不是懒惰求值的语言中使用 例如 在C 11中 可以通过将std launch deferred启动策略传递给std async以及计算值的函数来创建这种惰性future 演员模型中的future语义 编辑在演员模型中 形式为future lt Expression gt 的表达式由它对Eval消息 环境为E 客户为C 的响应方式定义 future表达式通过向客户C发送新创建的演员来响应Eval消息F 计算 lt Expression gt 的响应的代理 作为返回值 与此同时 向 lt Expression gt 发送环境E和客户C的Eval消息 F的默认行为如下 当F收到请求R时 它会通过评估 lt Expression gt 继续检查它是否已收到响应 可以是返回值或抛出异常 如下所示 如果它已经有响应V 那么 如果V是返回值 则发送给请求R 如果V是一个异常 那么就会把这个异常抛给请求R的客户 如果它还没有响应 则R存储在F内的请求队列中 当F从评估 lt Expression gt 接到响应V时 则V存储在F中 如果V是返回值 则将V发送到所有排队的请求 如果V是一个异常 那么就会把这个异常抛出给每个排队请求的客户 但是 一些future可以通过特殊方式处理请求以提供更大的并行性 例如 表达式1 future factorial n 可以创建一个新的future 其行为类似于数字1 factorial n 这个技巧并不总是有效 例如 以下条件表达式 if m gt future factorial n then print bigger else print smaller 会挂起 直到factorial n 这个future已回应询问m是否大于其自身的请求 历史 编辑 future 与 promise 构造首先在诸如MultiLisp和Act 1之类的编程语言中实现 在并发逻辑编程语言中使用逻辑变量进行通信非常类似于future 这些开始于 Prolog with Freeze 和 IC Prolog 并成为真正的并发原语 包括关系语言 Concurrent Prolog 守卫霍恩子句 GHC Parlog Strand Vulcan Janus Oz Mozart Flow Java和Alice ML 来自数据流编程语言的单一赋值 I var 源自Id并包含在Reppy的 Concurrent ML 中 非常类似于并发逻辑变量 promise流水线技术 使用future来克服延迟 是Barbara Liskov和Liuba Shrira于1988年发明的 9 由Mark S Miller Dean Tribble和Rob Jellinghaus在大约1989年的Xanadu项目中独立发明 17 promise 一词是由Liskov和Shrira创造的 尽管他们通过名称 call stream 引用了流水线机制 现在很少使用它 Liskov和Shrira的论文中描述的设计以及Xanadu中的promise流水线的实现都有一个限制 即promise值不是一等的 一个参数 或者一个call或send返回的值不能直接成为一个promise 所以前面给出的promise流水线的例子 它使用一个发送的结果作为另一个发送的参数的承诺 在call stream设计或Xanadu实现中不能直接表达 似乎promise和call stream从未在Argus的任何公开发布中实现 18 Liskov和Shrira论文中使用的编程语言 Argus的开发在1988年左右停止了 19 Xanadu实现的promise流水线仅在1999年Udanax Gold 20 的源代码发布时才公开发布 并且在任何已发布的文档中都没有解释过 21 Joule和E的后续实现支持完全一等的promise和resolver 一些早期的演员语言 包括Act系列 22 23 支持并行消息传递和流水线消息处理 但不支持promise流水线 虽然技术上可以在前两个中实现最后一个功能 但没有证据表明Act语言这样做了 2000年之后 由于消息传递的请求 响应模型 future和promise在用户界面响应和web开发中的应用重新引起了人们的兴趣 现在有几种主流语言对future和promise都有语言支持 最着名的是Java 5中的FutureTask 2004年公布 24 以及 NET 4 5中的async和await结构 2010年发布 2012年发布 25 26 很大程度上受到F 的 异步工作流程 可追溯到2007年 27 的启发 28 随后被其他语言采用 特别是Dart 2014 29 Python 2015 30 Hack HHVM 以及ECMAScript 7 JavaScript Scala和C 的草案 实现列表 编辑支持future promise 并发逻辑变量 数据流变量或I vars的语言 无论是通过直接语言支持还是在标准库中 包括 FreeFuture 通过FreeFuture 31 ABCL f 32 Alice ML AmbientTalk 包含一流的解析器和只读promise C 从C 11开始 std future和std promise mC Compositional C Crystal语言 Dart 使用Future Completer类 33 以及关键字await和async 29 Elm语言通过Task模块 34 Glasgow Haskell 仅限I vars和M vars Id 仅限I vars和M vars Io 35 Java通过Future 5 或CompletableFuture 6 Flow Java JavaScript 有限 从ECMAScript 6起支持 Lucid 仅限数据流 一些Lisp Clojure 36 MultiLisp NET通过Tasks C 自 NET 4 5起 25 通过关键字async与await 26 Nim Oxygene Oz版本3 37 Perl 6 38 Python concurrent futures 39 自从版本3 2 40 由PEP 3148所提议 41 而Python 3 5增加了async和await 42 R 延迟计算的promise 仍然是单线程 Racket 43 Scala通过scala concurrent包 44 Scheme Squeak Smalltalk Strand Swift 仅通过第三方库 Visual Basic 11 通过关键字Async和Await 26 还支持promise流水线的语言包括 E Joule 基于非标准库的future实现 对于Common Lisp Blackbird 45 Eager Future2 46 lparallel 47 PCall 48 对于C Boost library 49 Dlib 50 Qt 51 Seastar 52 Folly 53 POCO C Libraries Active Results 54 对于C 和其他 NET语言 Parallel Extensions库 对于Groovy GPars 55 对于JavaScript Cujo js 56 when js 57 提供符合Promises A 58 1 1规范的promise Dojo Toolkit提供promises 59 和Twisted方式延迟 MochiKit 60 受Twisted s Deferreds的启发 jQuery 61 的Deferred Object 62 基于CommonJS Promises A 63 设计 Angularjs 64 node promise 65 Q 作者为Kris Kowal 符合Promises A 1 1 66 RSVP js 符合Promises A 1 1 67 YUI的 68 promise类 69 符合Promises A 1 0规范 Bluebird 作者Petka Antonov 70 Closure Library的promise 71 包符合Promises A 规范 有关基于Promise A 设计的更多实现 请参阅Promise A 72 列表 对于Java JDeferred提供了与JQuery类似的deferred promise API和行为 Deferred对象 73 ParSeq 74 提供task promise API 由LinkedIn维护 适用于异步流水线和分支 对于Objective C MAFuture 75 76 RXPromise 77 ObjC CollapsingFutures 78 PromiseKit 79 objc promise 80 OAPromise 81 对于OCaml Lazy模块实现了懒惰的显式期货 82 对于Perl Future 83 Promises 84 和Reflex 85 对于PHP React Promise 86 对于Python 内置实现 87 pythonfutures 88 Twisted s Deferreds 89 对于R future 实现可扩展的future API与懒惰和及早同步和 多核或分布式 异步期货 90 90 对于Ruby Promise gem 91 libuv gem 实现promise 92 Celluloid gem 实现future 93 future resource 94 对于Rust futures rs 95 对于Scala Twitter的util库 96 对于Swift 异步框架 实现C 风格的async 非阻塞await 97 FutureKit 98 实现了Apple GCD的版本 99 FutureLib 纯Swift 2库实现的Scala风格的future和promise与TPL风格的取消 100 Deferred 纯Swift库 受到OCaml的Deferred启发 101 BrightFutures 102 对于Tcl tcl promise 103 协程 编辑 future可以用协程 30 或生成器实现 104 从而产生相同的评估策略 例如 协同多任务或延迟评估 通道 编辑 主条目 通道 编程 future可以很容易地用通道实现 future是一个单元素的通道 而promise是一个发送到通道 实现future的过程 105 106 这允许future在支持通道 如CSP和Go 的并发编程语言中实现 由此产生的future是显式的 因为它们必须通过从通道读取而不是仅仅通过评估来获取 参见 编辑纤程 Futex参考资料 编辑 Friedman Daniel David Wise The Impact of Applicative Programming on Multiprocessing International Conference on Parallel Processing 263 272 1976 Hibbard Peter Parallel Processing Facilities New Directions in Algorithmic Languages ed Stephen A Schuman IRIA 1976 1976 Henry Baker Carl Hewitt The Incremental Garbage Collection of Processes Proceedings of the Symposium on Artificial Intelligence Programming Languages ACM Sigplan Notices 12 8 55 59 August 1977 2018 12 31 原始内容存档于2008 07 04 SIP 14 Futures and Promises 页面存档备份 存于互联网档案馆 5 0 5 1 java util concurrent Future 6 0 6 1 java util concurrent CompletableFuture Promise Pipelining www erights org 2018 12 31 原始内容存档于2018 10 22 Promise Pipelining on the C2 wiki 2018 12 31 原始内容存档于2005 09 25 9 0 9 1 Barbara Liskov Liuba Shrira Promises Linguistic Support for Efficient Asynchronous Procedure Calls in Distributed Systems Proceedings of the SIGPLAN 88 Conference on Programming Language Design and Implementation Atlanta Georgia United States ACM 260 267 1988 ISBN 0 89791 269 1 doi 10 1145 53990 54016 Also published in ACM SIGPLAN Notices 23 7 Robust promises with Dojo deferred Site Pen 2010 05 03 2018 12 31 原始内容存档于2018 12 31 11 0 11 1 Promise Alice Manual DE Uni SB 2018 12 31 原始内容存档于2008 10 08 12 0 12 1 Future Alice manual DE Uni SB 2018 12 31 原始内容存档于2008 10 06 Promise E rights 2018 12 31 原始内容存档于2018 12 31 500 lines or less A Web Crawler With asyncio Coroutines by A Jesse Jiryu Davis and Guido van Rossum 页面存档备份 存于互联网档案馆 says implementation uses an asyncio Event in place of the Future shown here The difference is an Event can be reset whereas a Future cannot transition from resolved back to pending Control Concurrent MVar Haskell 2018 12 31 原始内容存档于2009 04 18 WaitNeeded Mozart Oz 2018 12 31 原始内容存档于2013 05 17 Promise Sunless Sea 2018 12 31 原始内容存档于2007 10 23 Argus MIT 2018 12 31 原始内容存档于2018 04 27 Liskov Barbara Distributed computing and Argus Oral history IEEE GHN 2018 12 31 原始内容存档于2014 11 22 Gold Udanax 2018 12 31 原始内容存档于2008 10 11 Pipeline E rights 2018 12 31 原始内容存档于2018 10 22 Henry Lieberman A Preview of Act 1 MIT AI memo 625 June 1981 Henry Lieberman Thinking About Lots of Things at Once without Getting Confused Parallelism in Act 1 MIT AI memo 626 June 1981 Goetz Brian Concurrency in JDK 5 0 2004 11 23 原始内容存档于2018 11 13 25 0 25 1 Async in 4 5 Worth the Await NET Blog Site Home MSDN Blogs Blogs msdn com 2014 05 13 原始内容存档于2012 04 07 26 0 26 1 26 2 Asynchronous Programming with Async and Await C and Visual Basic Msdn microsoft com 2014 05 13 原始内容存档于2014 05 27 Don Syme Tomas Petricek Dmitry Lomov The F Asynchronous Programming Model PADL 2011 2010 10 21 2018 12 31 原始内容存档于2015 05 15 Tomas Petricek Asynchronous C and F I Simultaneous introduction 2010 10 29 2018 12 31 原始内容存档于2018 12 31 29 0 29 1 Gilad Bracha Dart Language Asynchrony Support Phase 1 October 2014 2018 12 31 原始内容存档于2016 07 02 30 0 30 1 PEP 0492 Coroutines with async and await syntax 2018 12 31 原始内容存档于2019 01 05 FreeFuture 页面存档备份 存于互联网档案馆 Kenjiro Taura Satoshi Matsuoka Akinori Yonezawa ABCL f A Future Based Polymorphic Typed Concurrent Object Oriented Language Its Design and Implementation In Proceedings of the DIMACS workshop on Specification of Parallel Algorithms number 18 in Dimacs Series in Discrete Mathematics and Theoretical Computer Science American Mathematical Society 275 292 1994 CiteSeerX 10 1 1 23 1161 nbsp Dart SDK dart async Completer 2018 12 31 原始内容存档于2016 03 04 Task 2018 12 31 原始内容存档于2018 12 31 Steve Dekorte Io The Programming Language 2005 2018 12 31 原始内容存档于2019 01 04 Rich Hickey changes txt at 1 1 x from richhickey s clojure 2009 2018 12 31 原始内容存档于2016 02 18 Seif Haridi Nils Franzen Tutorial of Oz Mozart Global User Library 2011 04 12 原始内容存档于2011 05 14 Perl 6中的Promise类 docs perl6 org 2019 01 04 原始内容存档于2018 12 31 concurrent futures 页面存档备份 存于互联网档案馆 Python 3 2 发布 Python org 2018 12 31 原始内容存档于2018 12 31 PEP 3148 页面存档备份 存于互联网档案馆 Python 3 5 0 发布 Python org 2018 12 31 原始内容存档于2019 01 05 Parallelism with Futures PLT 2012 03 02 原始内容存档于2012 03 23 scala concurrent包 页面存档备份 存于互联网档案馆 Blackbird promise library Blackbird orthecreedence github io 2018 12 31 原始内容存档于2017 11 10 Eager Future2 common lisp net 2019 01 04 原始内容存档于2018 12 31 Common Lisp的并行编程库 永久失效連結 PCall marijnhaverbeke nl 2018 12 31 原始内容存档于2020 08 06 Chapter 30 Thread 4 0 0 2013 06 26 原始内容存档于2019 10 16 Dlib C Library thread pool 2013 06 26 原始内容存档于2019 10 16 QtCore 5 0 QFuture Class Qt Project 2013 06 26 原始内容存档于2013 06 01 Seastar Seastar project 2016 08 22 原始内容存档于2016 08 20 GitHub facebook folly An open source C library developed and used at Facebook 2018 12 31 原始内容存档于2019 03 22 Threads Slides of POCO PDF 2018 12 31 原始内容存档 PDF 于2020 05 08 Groovy GPars 2018 12 31 原始内容存档于2013 01 12 cujoJS Javascript architectural toolkit cujojs com 2019 01 04 原始内容存档于2012 03 17 A solid fast Promises A and when implementation plus other async goodies cujojs when 2018 12 25 2018 12 31 原始内容存档于2019 01 16 通过GitHub Promises A promisesaplus com 2019 01 04 原始内容存档于2018 12 29 Dojo Deferreds and Promises Archived Tutorial Dojo Toolkit dojotoolkit org 2019 01 04 原始内容存档于2018 12 31 manage asynchronous tasks MochiKit Async 2019 01 04 原始内容存档于2018 12 31 jQuery 2018 12 31 原始内容存档于2012 02 29 存档副本 2018 12 31 原始内容存档于2012 02 29 Deferred Object CommonJS Promises A 页面存档备份 存于互联网档案馆 AngularJS Superheroic JavaScript MVW Framework angularjs org 2019 01 04 原始内容存档于2015 06 23 Promise utilities for Node Contribute to kriszyp node promise development by creating an account on GitHub 2018 10 22 2018 12 31 原始内容存档于2019 05 27 通过GitHub kriskowal q documentup com 2018 12 31 原始内容存档于2018 12 31 A lightweight library that provides tools for organizing asynchronous code tildeio rsvp js 2019 01 03 2018 12 31 原始内容存档于2019 01 17 通过GitHub YUI Javascript 类库 yuilibrary com 2019 01 04 原始内容存档于2019 01 12 Promise YUI Library yuilibrary com 2019 01 04 原始内容存档于2018 12 31 bird zap Bluebird is a full featured promise library with unmatched performance petkaantonov bluebird 2019 01 04 2018 12 31 原始内容存档于2018 12 28 通过GitHub promise 页面存档备份 存于互联网档案馆 Promise A 页面存档备份 存于互联网档案馆 JDeferred JDeferred 2019 01 04 原始内容存档于2019 01 08 Asynchronous Java made easier Contribute to linkedin parseq development by creating an account on GitHub 2018 12 29 2018 12 31 原始内容存档于2018 06 10 通过GitHub Proxying futures library for Objective C Contribute to mikeash MAFuture development by creating an account on GitHub 2019 01 01 2018 12 31 原始内容存档于2019 02 13 通过GitHub mikeash com Friday Q amp A 2010 02 26 Futures www mikeash com 2019 01 04 原始内容存档于2018 12 31 An Objective C Class which implements the Promises A specification couchdeveloper RXPromise 2018 12 26 2018 12 31 原始内容存档于2018 06 11 通过GitHub Futures for Objective C that automatically collapse so it s nearly impossible to mix up the level of future nesting despite the lack of generics Strilanc ObjC CollapsingFutures 2018 12 07 2018 12 31 原始内容存档于2018 06 11 通过GitHub Promises for Swift amp ObjC Contribute to mxcl PromiseKit development by creating an account on GitHub 2019 01 03 2019 01 04 原始内容存档于2019 01 08 通过GitHub Objective C Promises in the CommonJS style Contribute to mproberts objc promise development by creating an account on GitHub 2018 09 11 2018 12 31 原始内容存档于2018 06 11 通过GitHub OAPromise is an API separating async operations and their callbacks adding consistency and useful features like fall through errors and progress reports oleganza OAPromise 2017 03 29 2018 12 31 原始内容存档于2013 10 27 通过GitHub Lazy caml inria fr 2018 12 31 原始内容存档于2015 07 06 Future represent an operation awaiting completion metacpan org metacpan org 2019 01 04 原始内容存档于2019 01 01 Promises An implementation of Promises in Perl metacpan org metacpan org 2018 12 31 原始内容存档于2018 12 31 Reflex Class library for flexible reactive programs metacpan org metacpan org 2019 01 04 原始内容存档于2019 01 04 Promises A implementation for PHP Contribute to reactphp promise development by creating an account on GitHub 2019 01 04 2018 12 31 原始内容存档于2019 04 07 通过GitHub Coroutines and Tasks Python 3 7 2 documentation docs python org 2018 12 31 原始内容存档于2018 12 31 Google Code Archive Long term storage for Google Code Project Hosting code google com 2019 01 04 原始内容存档于2020 08 06 Deferred Reference Twisted 18 9 0 documentation twistedmatrix com 2019 01 04 原始内容存档于2018 12 31 90 0 90 1 Bengtsson Henrik future Unified Parallel and Distributed Processing in R for Everyone 2018 10 17 2018 12 31 原始内容存档于2019 10 16 通过R Packages promise RubyGems org your community gem host rubygems org 2019 01 04 原始内容存档于2018 12 31 Ruby bindings for libuv Contribute to cotag libuv development by creating an account on GitHub 2018 10 16 2018 12 31 原始内容存档于2018 06 11 通过GitHub Celluloid Actor based Concurrent Objects for Ruby celluloid io 2019 01 04 原始内容存档于2018 12 31 Wait on resources being set in the future Contribute to adhearsion future resource development by creating an account on GitHub 2013 12 27 2018 12 31 原始内容存档于2018 06 11 通过GitHub Zero cost asynchronous programming in Rust Contribute to rust lang nursery futures rs development by creating an account on GitHub 2019 01 04 2019 01 04 原始内容存档于2019 02 26 通过GitHub Util twitter github io 2018 12 31 原始内容存档于2018 12 23 al45tair Async bitbucket org 2018 12 31 原始内容存档于2018 12 31 A Swift based Future Promises Library for IOS and OS X FutureKit FutureKit 2018 12 31 2018 12 31 原始内容存档于2018 08 10 通过GitHub Dispatch Apple Developer Documentation developer apple com 2019 01 04 原始内容存档于2018 12 31 FutureLib is a pure Swift 2 library implementing Futures amp Promises inspired by Scala couchdeveloper FutureLib 2018 10 15 2018 12 31 原始内容存档于2018 06 12 通过GitHub Work with values that haven t been determined yet bignerdranch Deferred 2019 01 02 2019 01 04 原始内容存档于2018 06 10 通过GitHub Write great asynchronous code in Swift using futures and promises Thomvis BrightFutures 2019 01 03 2018 12 31 原始内容存档于2018 06 11 通过GitHub tcl promise SourceForge 2018 12 31 原始内容存档于2018 12 31 Does async await solve a real problem esdiscuss org 2018 12 31 原始内容存档于2018 11 13 Futures Go Language Patterns www golangpatterns info 2019 01 04 原始内容存档于2019 01 04 Go Language Patterns www golangpatterns info 2019 01 04 原始内容存档于2019 01 04 外部链接 编辑Concurrency patterns presentation 页面存档备份 存于互联网档案馆 given at scaleconf 页面存档备份 存于互联网档案馆 Future Value 页面存档备份 存于互联网档案馆 and Promise Pipelining 页面存档备份 存于互联网档案馆 at the Portland Pattern Repository Easy Threading with Futures 页面存档备份 存于互联网档案馆 in Python 取自 https zh wikipedia org w index php title Future与promise amp oldid 74454498, 维基百科,wiki,书籍,书籍,图书馆,

文章

,阅读,下载,免费,免费下载,mp3,视频,mp4,3gp, jpg,jpeg,gif,png,图片,音乐,歌曲,电影,书籍,游戏,游戏。