Futures and promises: Difference between revisions
Rescuing 8 sources and tagging 0 as dead.) #IABot (v2.0.8.6 |
m encyclopedic style |
||
(16 intermediate revisions by 12 users not shown) | |||
Line 1: | Line 1: | ||
{{Short description|Computer science constructs}} |
|||
{{distinguish|Promise theory}} |
{{distinguish|Promise theory}} |
||
{{Use dmy dates|date= |
{{Use dmy dates|date=November 2023}} |
||
In [[computer science]], '''future''', '''promise''', '''delay''', and '''deferred''' refer to constructs used for [[synchronization (computer science)|synchronizing]] program [[execution (computing)|execution]] in some [[concurrent programming language]]s. They describe an object that acts as a proxy for a result that is initially unknown, usually because the [[computation]] of its value is not yet complete. |
In [[computer science]], '''future''', '''promise''', '''delay''', and '''deferred''' refer to constructs used for [[synchronization (computer science)|synchronizing]] program [[execution (computing)|execution]] in some [[concurrent programming language]]s. They describe an object that acts as a proxy for a result that is initially unknown, usually because the [[computation]] of its value is not yet complete. |
||
Line 92: | Line 94: | ||
* In the [[Dojo Toolkit]]'s Deferred API as of version 1.5, a ''consumer-only promise object'' represents a read-only view.<ref>{{citation |url= http://www.sitepen.com/blog/2010/05/03/robust-promises-with-dojo-deferred-1-5/ |publisher= Site Pen |date= 2010-05-03 |title= Robust promises with Dojo deferred}}</ref> |
* In the [[Dojo Toolkit]]'s Deferred API as of version 1.5, a ''consumer-only promise object'' represents a read-only view.<ref>{{citation |url= http://www.sitepen.com/blog/2010/05/03/robust-promises-with-dojo-deferred-1-5/ |publisher= Site Pen |date= 2010-05-03 |title= Robust promises with Dojo deferred}}</ref> |
||
* In [[Alice ML]], futures provide a ''read-only view'', whereas a promise contains both a future and the ability to resolve the future<ref name= "Alice ML promise">{{citation |chapter-url= http://www.ps.uni-sb.de/alice/manual/library/promise.html |title= Alice Manual |chapter= Promise |publisher= Uni-SB |place= DE |access-date= 21 March 2007 |archive-date= 8 October 2008 |archive-url= https://web.archive.org/web/20081008005201/http://www.ps.uni-sb.de/alice/manual/library/promise.html |url-status= dead }}</ref><ref name= "Alice ML future">{{citation |chapter-url= http://www.ps.uni-sb.de/alice/manual/library/future.html |title= Alice manual |chapter= Future |publisher= Uni-SB |place= DE |access-date= 21 March 2007 |archive-date= 6 October 2008 |archive-url= https://web.archive.org/web/20081006231223/http://www.ps.uni-sb.de/alice/manual/library/future.html |url-status= dead }}</ref> |
* In [[Alice ML]], futures provide a ''read-only view'', whereas a promise contains both a future and the ability to resolve the future<ref name= "Alice ML promise">{{citation |chapter-url= http://www.ps.uni-sb.de/alice/manual/library/promise.html |title= Alice Manual |chapter= Promise |publisher= Uni-SB |place= DE |access-date= 21 March 2007 |archive-date= 8 October 2008 |archive-url= https://web.archive.org/web/20081008005201/http://www.ps.uni-sb.de/alice/manual/library/promise.html |url-status= dead }}</ref><ref name= "Alice ML future">{{citation |chapter-url= http://www.ps.uni-sb.de/alice/manual/library/future.html |title= Alice manual |chapter= Future |publisher= Uni-SB |place= DE |access-date= 21 March 2007 |archive-date= 6 October 2008 |archive-url= https://web.archive.org/web/20081006231223/http://www.ps.uni-sb.de/alice/manual/library/future.html |url-status= dead }}</ref> |
||
* In [[.NET |
* In [[.NET]] <code>System.Threading.Tasks.Task<T></code> represents a read-only view. Resolving the value can be done via <code>System.Threading.Tasks.TaskCompletionSource<T></code>. |
||
Support for read-only views is consistent with the [[principle of least privilege]], since it enables the ability to set the value to be restricted to [[Subject (access control)|subjects]] that need to set it. In a system that also supports pipelining, the sender of an asynchronous message (with result) receives the read-only promise for the result, and the target of the message receives the resolver. |
Support for read-only views is consistent with the [[principle of least privilege]], since it enables the ability to set the value to be restricted to [[Subject (access control)|subjects]] that need to set it. In a system that also supports pipelining, the sender of an asynchronous message (with result) receives the read-only promise for the result, and the target of the message receives the resolver. |
||
Line 110: | Line 112: | ||
* potentially, the access could succeed if the future is already resolved, but signal an error if it is not. This would have the disadvantage of introducing nondeterminism and the potential for [[race conditions]], and seems to be an uncommon design choice. |
* potentially, the access could succeed if the future is already resolved, but signal an error if it is not. This would have the disadvantage of introducing nondeterminism and the potential for [[race conditions]], and seems to be an uncommon design choice. |
||
As an example of the first possibility, in [[C++11]], a thread that needs the value of a future can block until it is available by calling the <code>wait()</code> or <code>get()</code> member functions. |
As an example of the first possibility, in [[C++11]], a thread that needs the value of a future can block until it is available by calling the <code>wait()</code> or <code>get()</code> member functions. A timeout can also be specified on the wait using the <code>wait_for()</code> or <code>wait_until()</code> member functions to avoid indefinite blocking. If the future arose from a call to <code>std::async</code> then a blocking wait (without a timeout) may cause synchronous invocation of the function to compute the result on the waiting thread. |
||
==Related constructs== |
==Related constructs== |
||
'' |
''Futures'' are a particular case of the [[synchronization primitive]] "[[Event (synchronization primitive)|events]]," which can be completed only once. In general, events can be reset to initial empty state and, thus, completed as many times as desired.<ref>[http://aosabook.org/en/500L/a-web-crawler-with-asyncio-coroutines.html#fn13 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."</ref> |
||
An ''I-var'' (as in the language [[Id (programming language)|Id]]) is a future with blocking semantics as defined above. An ''I-structure'' is a [[data structure]] containing I-vars. A related synchronization construct that can be set multiple times with different values is called an ''M-var''. M-vars support atomic operations to ''take'' or ''put'' the current value, where taking the value also sets the M-var back to its initial ''empty'' state.<ref>{{citation |url= http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent-MVar.html |publisher= Haskell |title= Control Concurrent MVar |url-status= dead |archive-url= https://web.archive.org/web/20090418025331/http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent-MVar.html |archive-date= 18 April 2009 |
An ''I-var'' (as in the language [[Id (programming language)|Id]]) is a future with blocking semantics as defined above. An ''I-structure'' is a [[data structure]] containing I-vars. A related synchronization construct that can be set multiple times with different values is called an ''M-var''. M-vars support atomic operations to ''take'' or ''put'' the current value, where taking the value also sets the M-var back to its initial ''empty'' state.<ref>{{citation |url= http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent-MVar.html |publisher= Haskell |title= Control Concurrent MVar |url-status= dead |archive-url= https://web.archive.org/web/20090418025331/http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent-MVar.html |archive-date= 18 April 2009 }}</ref> |
||
A ''concurrent logic variable'' {{Citation needed|reason=It is not obvious to the reader where a definition and description of a concurrent logic variable can be found.|date=March 2018}} is similar to a future, but is updated by [[Unification (computing)|unification]], in the same way as ''logic variables'' in [[logic programming]]. Thus it can be bound more than once to unifiable values, but cannot be set back to an empty or unresolved state. The dataflow variables of Oz act as concurrent logic variables, and also have blocking semantics as mentioned above. |
A ''concurrent logic variable'' {{Citation needed|reason=It is not obvious to the reader where a definition and description of a concurrent logic variable can be found.|date=March 2018}} is similar to a future, but is updated by [[Unification (computing)|unification]], in the same way as ''logic variables'' in [[logic programming]]. Thus it can be bound more than once to unifiable values, but cannot be set back to an empty or unresolved state. The dataflow variables of Oz act as concurrent logic variables, and also have blocking semantics as mentioned above. |
||
Line 158: | Line 160: | ||
The term ''promise'' was coined by Liskov and Shrira, although they referred to the pipelining mechanism by the name ''call-stream'', which is now rarely used. |
The term ''promise'' was coined by Liskov and Shrira, although they referred to the pipelining mechanism by the name ''call-stream'', which is now rarely used. |
||
Both the design described in Liskov and Shrira's paper, and the implementation of promise pipelining in Xanadu, had the limit that promise values were not [[first-class value|first-class]]: an argument to, or the value returned by a call or send could not directly be a promise (so the example of promise pipelining given earlier, which uses a promise for the result of one send as an argument to another, would not have been directly expressible in the call-stream design or in the Xanadu implementation). It seems that promises and call-streams were never implemented in any public release of Argus,<ref>{{citation |url= http://www.pmg.csail.mit.edu/Argus.html |publisher= MIT |title= Argus}}</ref> the programming language used in the Liskov and Shrira paper. Argus development stopped around 1988.<ref>{{citation |url= http://www.ieeeghn.org/wiki/index.php/Oral-History:Barbara_Liskov#Distributed_Computing_and_Argus |publisher= IEEE GHN |series= Oral history |first= Barbara |last= Liskov |title= Distributed computing and Argus}}</ref> The Xanadu implementation of promise pipelining only became publicly available with the release of the source code for Udanax Gold<ref>{{citation |url= http://www.udanax.com/gold/ |publisher= Udanax |title= Gold |url-status= dead |archive-url= https://web.archive.org/web/20081011003837/http://www.udanax.com/gold/ |archive-date= 11 October 2008 |
Both the design described in Liskov and Shrira's paper, and the implementation of promise pipelining in Xanadu, had the limit that promise values were not [[first-class value|first-class]]: an argument to, or the value returned by a call or send could not directly be a promise (so the example of promise pipelining given earlier, which uses a promise for the result of one send as an argument to another, would not have been directly expressible in the call-stream design or in the Xanadu implementation). It seems that promises and call-streams were never implemented in any public release of Argus,<ref>{{citation |url= http://www.pmg.csail.mit.edu/Argus.html |publisher= MIT |title= Argus}}</ref> the programming language used in the Liskov and Shrira paper. Argus development stopped around 1988.<ref>{{citation |url= http://www.ieeeghn.org/wiki/index.php/Oral-History:Barbara_Liskov#Distributed_Computing_and_Argus |publisher= IEEE GHN |series= Oral history |first= Barbara |last= Liskov |title= Distributed computing and Argus|date= 26 January 2021 }}</ref> The Xanadu implementation of promise pipelining only became publicly available with the release of the source code for Udanax Gold<ref>{{citation |url= http://www.udanax.com/gold/ |publisher= Udanax |title= Gold |url-status= dead |archive-url= https://web.archive.org/web/20081011003837/http://www.udanax.com/gold/ |archive-date= 11 October 2008 }}</ref> in 1999, and was never explained in any published document.<ref>{{citation |url= http://www.erights.org/elib/distrib/pipeline.html |publisher= E rights |title= Pipeline}}</ref> The later implementations in Joule and E support fully first-class promises and resolvers. |
||
Several early actor languages, including the Act series,<ref>{{cite journal |
Several early actor languages, including the Act series,<ref>{{cite journal |
||
⚫ | |author=Henry Lieberman |title=A Preview of Act 1 |date=June 1981 |journal=MIT AI Memo 625}}</ref><ref>{{cite journal|author=Henry Lieberman |title=Thinking About Lots of Things at Once without Getting Confused: Parallelism in Act 1 |date=June 1981 |journal=MIT AI Memo 626}}</ref> supported both parallel message passing and pipelined message processing, but not promise pipelining. (Although it is technically possible to implement the last of these features in the first two, there is no evidence that the Act languages did so.) |
||
| author= Henry Lieberman |
|||
| title= A Preview of Act 1 |
|||
|date=June 1981 |
|||
| publisher= MIT AI memo 625 |
|||
}}</ref><ref>{{cite journal |
|||
| author= Henry Lieberman |
|||
| title= Thinking About Lots of Things at Once without Getting Confused: Parallelism in Act 1 |
|||
|date=June 1981 |
|||
| publisher= MIT AI memo 626 |
|||
⚫ | |||
After 2000, a major revival of interest in futures and promises occurred, due to their use in [[responsiveness]] of user interfaces, and in [[web development]], due to the [[request–response]] model of message-passing. Several mainstream languages now have language support for futures and promises, most notably popularized by <code>FutureTask</code> in Java 5 (announced 2004)<ref>{{Cite web|url=https://www.ibm.com/developerworks/java/tutorials/j-concur/j-concur.html|title=Concurrency in JDK 5.0|last=Goetz|first=Brian| |
After 2000, a major revival of interest in futures and promises occurred, due to their use in [[responsiveness]] of user interfaces, and in [[web development]], due to the [[request–response]] model of message-passing. Several mainstream languages now have language support for futures and promises, most notably popularized by <code>FutureTask</code> in Java 5 (announced 2004)<ref>{{Cite web|url=https://www.ibm.com/developerworks/java/tutorials/j-concur/j-concur.html|title=Concurrency in JDK 5.0|last=Goetz|first=Brian|website=[[IBM]] |date=23 November 2004}}</ref> and the [[async/await]] constructions in .NET 4.5 (announced 2010, released 2012)<ref name="asyncdotnet45">{{cite web|url=http://blogs.msdn.com/b/dotnet/archive/2012/04/03/async-in-4-5-worth-the-await.aspx |title=Async in 4.5: Worth the Await – .NET Blog – Site Home – MSDN Blogs |publisher=Blogs.msdn.com |access-date=2014-05-13}}</ref><ref name="dotnetasyncawait">{{cite web|url=http://msdn.microsoft.com/en-us/library/hh191443.aspx |title=Asynchronous Programming with Async and Await (C# and Visual Basic) |publisher=Msdn.microsoft.com |access-date=2014-05-13}}</ref> largely inspired by the ''asynchronous workflows'' of F#,<ref>{{cite web |
||
|title=Asynchronous C# and F# (I.): Simultaneous introduction |
|title=Asynchronous C# and F# (I.): Simultaneous introduction |
||
|url=http://tomasp.net/blog/csharp-fsharp-async-intro.aspx/ |
|url=http://tomasp.net/blog/csharp-fsharp-async-intro.aspx/ |
||
Line 180: | Line 173: | ||
|title=The F# Asynchronous Programming Model, PADL 2011 |
|title=The F# Asynchronous Programming Model, PADL 2011 |
||
|url=http://blogs.msdn.com/b/dsyme/archive/2010/10/21/the-f-asynchronous-programming-model-padl-2010-pre-publication-draft.aspx |
|url=http://blogs.msdn.com/b/dsyme/archive/2010/10/21/the-f-asynchronous-programming-model-padl-2010-pre-publication-draft.aspx |
||
|date=21 |
|date=21 October 2010 |
||
|author1=Don Syme |
|author1=Don Syme |
||
|author2=Tomas Petricek |
|author2=Tomas Petricek |
||
Line 187: | Line 180: | ||
|title=PEP 0492 – Coroutines with async and await syntax |
|title=PEP 0492 – Coroutines with async and await syntax |
||
|url=https://www.python.org/dev/peps/pep-0492/ |
|url=https://www.python.org/dev/peps/pep-0492/ |
||
}}</ref> Hack (HHVM), and drafts of ECMAScript 7 (JavaScript), Scala, and C++. |
}}</ref> Hack (HHVM), and drafts of ECMAScript 7 (JavaScript), Scala, and C++ (2011). |
||
==List of implementations== |
==List of implementations== |
||
Line 254: | Line 247: | ||
* [[.NET Framework|.NET]] via ''Task''s |
* [[.NET Framework|.NET]] via ''Task''s |
||
** [[C Sharp (programming language)|C#]], since .NET Framework 4.5,<ref name="asyncdotnet45"/> via the keywords <code>async</code> and <code>await</code><ref name="dotnetasyncawait"/> |
** [[C Sharp (programming language)|C#]], since .NET Framework 4.5,<ref name="asyncdotnet45"/> via the keywords <code>async</code> and <code>await</code><ref name="dotnetasyncawait"/> |
||
* [[Kotlin (programming language)|Kotlin]], however <code>kotlin.native.concurrent.Future</code> is only usually used when writing Kotlin that is intended to run natively<ref>{{Cite web|url=https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.native.concurrent/-future/|title=Future |
* [[Kotlin (programming language)|Kotlin]], however <code>kotlin.native.concurrent.Future</code> is only usually used when writing Kotlin that is intended to run natively<ref>{{Cite web|url=https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.native.concurrent/-future/|title=Future – Kotlin Programming Language}}</ref> |
||
* [[Nim (programming language)|Nim]] |
* [[Nim (programming language)|Nim]] |
||
* [[Oxygene (programming language)|Oxygene]] |
* [[Oxygene (programming language)|Oxygene]] |
||
Line 261: | Line 254: | ||
* [[R (programming language)|R]] (promises for lazy evaluation, still single threaded) |
* [[R (programming language)|R]] (promises for lazy evaluation, still single threaded) |
||
* [[Racket (programming language)|Racket]]<ref>{{cite web|url=http://docs.racket-lang.org/guide/performance.html#(part._effective-futures)|title=Parallelism with Futures|publisher=PLT|access-date=2 March 2012}}</ref> |
* [[Racket (programming language)|Racket]]<ref>{{cite web|url=http://docs.racket-lang.org/guide/performance.html#(part._effective-futures)|title=Parallelism with Futures|publisher=PLT|access-date=2 March 2012}}</ref> |
||
* [[Raku (programming language)|Raku]]<ref> |
* [[Raku (programming language)|Raku]]<ref>{{cite web|url=https://docs.raku.org/type/Promise|title=class Promise|publisher=raku.org|access-date=2022-08-19}}</ref> |
||
* [[Rust (programming language)|Rust]] (usually achieved via <code>.await</code>)<ref>{{Cite web|url=https://doc.rust-lang.org/std/future/trait.Future.html |
* [[Rust (programming language)|Rust]] (usually achieved via <code>.await</code>)<ref>{{Cite web |title=Future in std::future - Rust |url=https://doc.rust-lang.org/std/future/trait.Future.html |access-date=2023-12-16 |website=doc.rust-lang.org}}</ref> |
||
* [[Scala (programming language)|Scala]] via [http://docs.scala-lang.org/overviews/core/futures.html scala.concurrent package] |
* [[Scala (programming language)|Scala]] via [http://docs.scala-lang.org/overviews/core/futures.html scala.concurrent package] |
||
* [[Scheme (programming language)|Scheme]] |
* [[Scheme (programming language)|Scheme]] |
||
Line 274: | Line 267: | ||
* [[Joule (programming language)|Joule]] |
* [[Joule (programming language)|Joule]] |
||
===List of |
===List of library-based implementations of futures=== |
||
* For [[Common Lisp]]: |
* For [[Common Lisp]]: |
||
** Blackbird<ref>[https://orthecreedence.github.io/blackbird/ Common Lisp Blackbird]</ref> |
** Blackbird<ref>[https://orthecreedence.github.io/blackbird/ Common Lisp Blackbird]</ref> |
||
Line 290: | Line 283: | ||
|access-date=26 June 2013}}</ref> |
|access-date=26 June 2013}}</ref> |
||
** Folly<ref>{{cite web|url=https://github.com/facebook/folly|title=GitHub – facebook/folly: An open-source C++ library developed and used at Facebook.|website=[[GitHub]]|date=2019-01-08}}</ref> |
** Folly<ref>{{cite web|url=https://github.com/facebook/folly|title=GitHub – facebook/folly: An open-source C++ library developed and used at Facebook.|website=[[GitHub]]|date=2019-01-08}}</ref> |
||
** HPX |
** HPX<ref>{{cite web|url=http://stellar-group.org/libraries/hpx/|title=HPX|date=2019-02-10}}</ref> |
||
** [[POCO C++ Libraries]] (Active Results)<ref>{{cite web|url=https://pocoproject.org/slides/130-Threads.pdf|title=Threads Slides of POCO}}</ref> |
** [[POCO C++ Libraries]] (Active Results)<ref>{{cite web|url=https://pocoproject.org/slides/130-Threads.pdf|title=Threads Slides of POCO}}</ref> |
||
** [[Qt (software)|Qt]]<ref>{{cite web |
** [[Qt (software)|Qt]]<ref>{{cite web |
||
Line 329: | Line 322: | ||
* For [[Objective-C]]: MAFuture,<ref>[https://github.com/mikeash/MAFuture Objective-C MAFuture GitHub]</ref><ref>[http://www.mikeash.com/pyblog/friday-qa-2010-02-26-futures.html Objective-C MAFuture mikeash.com]</ref> RXPromise,<ref>[https://github.com/couchdeveloper/RXPromise Objective-C RXPromise]</ref> ObjC-CollapsingFutures,<ref>[https://github.com/Strilanc/ObjC-CollapsingFutures ObjC-CollapsingFutures]</ref> PromiseKit,<ref>[http://promisekit.org/ Objective-C PromiseKit]</ref> objc-promise,<ref>[https://github.com/mproberts/objc-promise Objective-C objc-promise]</ref> OAPromise,<ref>[https://github.com/oleganza/OAPromise Objective-C OAPromise]</ref> |
* For [[Objective-C]]: MAFuture,<ref>[https://github.com/mikeash/MAFuture Objective-C MAFuture GitHub]</ref><ref>[http://www.mikeash.com/pyblog/friday-qa-2010-02-26-futures.html Objective-C MAFuture mikeash.com]</ref> RXPromise,<ref>[https://github.com/couchdeveloper/RXPromise Objective-C RXPromise]</ref> ObjC-CollapsingFutures,<ref>[https://github.com/Strilanc/ObjC-CollapsingFutures ObjC-CollapsingFutures]</ref> PromiseKit,<ref>[http://promisekit.org/ Objective-C PromiseKit]</ref> objc-promise,<ref>[https://github.com/mproberts/objc-promise Objective-C objc-promise]</ref> OAPromise,<ref>[https://github.com/oleganza/OAPromise Objective-C OAPromise]</ref> |
||
* For [[OCaml]]: Lazy module implements lazy explicit futures<ref>[http://caml.inria.fr/pub/docs/manual-ocaml/libref/Lazy.html OCaml Lazy]</ref> |
* For [[OCaml]]: Lazy module implements lazy explicit futures<ref>[http://caml.inria.fr/pub/docs/manual-ocaml/libref/Lazy.html OCaml Lazy]</ref> |
||
* For [[Perl]]: Future,<ref>[http://metacpan.org/module/Future Perl Future]</ref> Promises,<ref>[https://metacpan.org/pod/Promises Perl Promises]</ref> Reflex,<ref>[http://metacpan.org/module/Reflex/ Perl Reflex]</ref> Promise::ES6,<ref>[http://metacpan.org/module/Promise::ES6/ Perl Promise::ES6]</ref> and Promise::XS<ref>{{Cite web|title=Promise::XS |
* For [[Perl]]: Future,<ref>[http://metacpan.org/module/Future Perl Future]</ref> Promises,<ref>[https://metacpan.org/pod/Promises Perl Promises]</ref> Reflex,<ref>[http://metacpan.org/module/Reflex/ Perl Reflex]</ref> Promise::ES6,<ref>[http://metacpan.org/module/Promise::ES6/ Perl Promise::ES6]</ref> and Promise::XS<ref>{{Cite web|title=Promise::XS – Fast promises in Perl – metacpan.org|url=https://metacpan.org/pod/Promise::XS|access-date=2021-02-14|website=metacpan.org}}</ref> |
||
* For [[PHP]]: React/Promise<ref>[https://github.com/reactphp/promise PHP React/Promise]</ref> |
* For [[PHP]]: React/Promise<ref>[https://github.com/reactphp/promise PHP React/Promise]</ref> |
||
* For [[Python (programming language)|Python]]: |
* For [[Python (programming language)|Python]]: |
||
** Built-in implementation<ref>[https://docs.python.org/3/library/asyncio-task.html#future Python built-in implementation]</ref> |
** Built-in implementation<ref>[https://docs.python.org/3/library/asyncio-task.html#future Python built-in implementation]</ref> |
||
** pythonfutures<ref>[http://code.google.com/p/pythonfutures/ pythonfutures]</ref> |
** pythonfutures<ref>[http://code.google.com/p/pythonfutures/ pythonfutures]</ref> |
||
** [[Twisted (software)|Twisted's]] Deferreds<ref> |
** [[Twisted (software)|Twisted's]] Deferreds<ref>{{Cite web |url=http://twistedmatrix.com/documents/current/core/howto/defer.html |title=Twisted Deferreds |access-date=29 April 2010 |archive-date=6 August 2020 |archive-url=https://web.archive.org/web/20200806202718/https://twistedmatrix.com/documents/current/core/howto/defer.html |url-status=dead }}</ref> |
||
* For [[R (programming language)|R]]: |
* For [[R (programming language)|R]]: |
||
** future, implements an extendable future API with lazy and eager synchronous and (multicore or distributed) asynchronous futures<ref>[https://cran.r-project.org/package=future R package future]</ref><ref>[https://cran.r-project.org/package=future future]</ref> |
** future, implements an extendable future API with lazy and eager synchronous and (multicore or distributed) asynchronous futures<ref>[https://cran.r-project.org/package=future R package future]</ref><ref>[https://cran.r-project.org/package=future future]</ref> |
||
* For [[Ruby (programming language)|Ruby]]: |
* For [[Ruby (programming language)|Ruby]]: |
||
** Concurrent Ruby<ref>[https://github.com/ruby-concurrency/concurrent-ruby Concurrent Ruby]</ref> |
|||
** Promise gem<ref>[http://rubygems.org/gems/promise Ruby Promise gem]</ref> |
** Promise gem<ref>[http://rubygems.org/gems/promise Ruby Promise gem]</ref> |
||
** libuv gem, implements promises<ref>[https://github.com/cotag/libuv Ruby libuv]</ref> |
** libuv gem, implements promises<ref>[https://github.com/cotag/libuv Ruby libuv]</ref> |
||
Line 360: | Line 354: | ||
===Channels=== |
===Channels=== |
||
{{main|Channel (programming)}} |
{{main|Channel (programming)}} |
||
Futures can easily be implemented in [[Channel (programming)|channels]]: a future is a one-element channel, and a promise is a process that sends to the channel, fulfilling the future.<ref> |
Futures can easily be implemented in [[Channel (programming)|channels]]: a future is a one-element channel, and a promise is a process that sends to the channel, fulfilling the future.<ref>{{Cite web |url=https://sites.google.com/site/gopatterns/concurrency/futures |title=Go language patterns Futures |access-date=9 February 2014 |archive-date=4 December 2020 |archive-url=https://web.archive.org/web/20201204060631/https://sites.google.com/site/gopatterns/concurrency/futures |url-status=dead }}</ref><ref>{{Cite web |url=https://sites.google.com/site/gopatterns |title=Go Language Patterns |access-date=9 February 2014 |archive-date=11 November 2020 |archive-url=https://web.archive.org/web/20201111222255/https://sites.google.com/site/gopatterns |url-status=dead }}</ref> This allows futures to be implemented in concurrent programming languages with support for channels, such as CSP and [[Go (programming language)|Go]]. The resulting futures are explicit, as they must be accessed by reading from the channel, rather than only evaluation. |
||
== See also == |
== See also == |
||
Line 368: | Line 362: | ||
== References == |
== References == |
||
{{Reflist |
{{Reflist}} |
||
== External links == |
== External links == |
Latest revision as of 22:36, 9 July 2024
In computer science, future, promise, delay, and deferred refer to constructs used for synchronizing program execution in some concurrent programming languages. They describe an object that acts as a proxy for a result that is initially unknown, usually because the computation of its value is not yet complete.
The term promise was proposed in 1976 by Daniel P. Friedman and David Wise,[1] and Peter Hibbard called it eventual.[2] A somewhat similar concept future was introduced in 1977 in a paper by Henry Baker and Carl Hewitt.[3]
The terms future, promise, delay, and deferred are often used interchangeably, although some differences in usage between future and promise are treated below. Specifically, when usage is distinguished, a future is a read-only placeholder view of a variable, while a promise is a writable, single assignment container which sets the value of the future. Notably, a future may be defined without specifying which specific promise will set its value, and different possible promises may set the value of a given future, though this can be done only once for a given future. In other cases a future and a promise are created together and associated with each other: the future is the value, the promise is the function that sets the value – essentially the return value (future) of an asynchronous function (promise). Setting the value of a future is also called resolving, fulfilling, or binding it.
Applications
[edit]Futures and promises originated in functional programming and related paradigms (such as logic programming) to decouple a value (a future) from how it was computed (a promise), allowing the computation to be done more flexibly, notably by parallelizing it. Later, it found use in distributed computing, in reducing the latency from communication round trips. Later still, it gained more use by allowing writing asynchronous programs in direct style, rather than in continuation-passing style.
Implicit vs. explicit
[edit]Use of futures may be implicit (any use of the future automatically obtains its value, as if it were an ordinary reference) or explicit (the user must call a function to obtain the value, such as the get
method of java.util.concurrent.Future
in Java). Obtaining the value of an explicit future can be called stinging or forcing. Explicit futures can be implemented as a library, whereas implicit futures are usually implemented as part of the language.
The original Baker and Hewitt paper described implicit futures, which are naturally supported in the actor model of computation and pure object-oriented programming languages like Smalltalk. The Friedman and Wise paper described only explicit futures, probably reflecting the difficulty of efficiently implementing implicit futures on stock hardware. The difficulty is that stock hardware does not deal with futures for primitive data types like integers. For example, an add instruction does not know how to deal with 3 + future factorial(100000)
. In pure actor or object languages this problem can be solved by sending future factorial(100000)
the message +[3]
, which asks the future to add 3
to itself and return the result. Note that the message passing approach works regardless of when factorial(100000)
finishes computation and that no stinging/forcing is needed.
Promise pipelining
[edit]The use of futures can dramatically reduce latency in distributed systems. For instance, futures enable promise pipelining,[4][5] as implemented in the languages E and Joule, which was also called call-stream[6] in the language Argus.
Consider an expression involving conventional remote procedure calls, such as:
t3 := ( x.a() ).c( y.b() )
which could be expanded to
t1 := x.a(); t2 := y.b(); t3 := t1.c(t2);
Each statement needs a message to be sent and a reply received before the next statement can proceed. Suppose, for example, that x
, y
, t1
, and t2
are all located on the same remote machine. In this case, two complete network round-trips to that machine must take place before the third statement can begin to execute. The third statement will then cause yet another round-trip to the same remote machine.
Using futures, the above expression could be written
t3 := (x <- a()) <- c(y <- b())
which could be expanded to
t1 := x <- a(); t2 := y <- b(); t3 := t1 <- c(t2);
The syntax used here is that of the language E, where x <- a()
means to send the message a()
asynchronously to x
. All three variables are immediately assigned futures for their results, and execution proceeds to subsequent statements. Later attempts to resolve the value of t3
may cause a delay; however, pipelining can reduce the number of round-trips needed. If, as in the prior example, x
, y
, t1
, and t2
are all located on the same remote machine, a pipelined implementation can compute t3
with one round-trip instead of three. Because all three messages are destined for objects which are on the same remote machine, only one request need be sent and only one response need be received containing the result. The send t1 <- c(t2)
would not block even if t1
and t2
were on different machines to each other, or to x
or y
.
Promise pipelining should be distinguished from parallel asynchronous message passing. In a system supporting parallel message passing but not pipelining, the message sends x <- a()
and y <- b()
in the above example could proceed in parallel, but the send of t1 <- c(t2)
would have to wait until both t1
and t2
had been received, even when x
, y
, t1
, and t2
are on the same remote machine. The relative latency advantage of pipelining becomes even greater in more complicated situations involving many messages.
Promise pipelining also should not be confused with pipelined message processing in actor systems, where it is possible for an actor to specify and begin executing a behaviour for the next message before having completed processing of the current message.
Read-only views
[edit]In some programming languages such as Oz, E, and AmbientTalk, it is possible to obtain a read-only view of a future, which allows reading its value when resolved, but does not permit resolving it:
- In Oz, the
!!
operator is used to obtain a read-only view. - In E and AmbientTalk, a future is represented by a pair of values called a promise/resolver pair. The promise represents the read-only view, and the resolver is needed to set the future's value.
- In C++11 a
std::future
provides a read-only view. The value is set directly by using astd::promise
, or set to the result of a function call usingstd::packaged_task
orstd::async
. - In the Dojo Toolkit's Deferred API as of version 1.5, a consumer-only promise object represents a read-only view.[7]
- In Alice ML, futures provide a read-only view, whereas a promise contains both a future and the ability to resolve the future[8][9]
- In .NET
System.Threading.Tasks.Task<T>
represents a read-only view. Resolving the value can be done viaSystem.Threading.Tasks.TaskCompletionSource<T>
.
Support for read-only views is consistent with the principle of least privilege, since it enables the ability to set the value to be restricted to subjects that need to set it. In a system that also supports pipelining, the sender of an asynchronous message (with result) receives the read-only promise for the result, and the target of the message receives the resolver.
Thread-specific futures
[edit]Some languages, such as Alice ML, define futures that are associated with a specific thread that computes the future's value.[9] This computation can start either eagerly when the future is created, or lazily when its value is first needed. A lazy future is similar to a thunk, in the sense of a delayed computation.
Alice ML also supports futures that can be resolved by any thread, and calls these promises.[8] This use of promise is different from its use in E as described above. In Alice, a promise is not a read-only view, and promise pipelining is unsupported. Instead, pipelining naturally happens for futures, including ones associated with promises.
Blocking vs non-blocking semantics
[edit]If the value of a future is accessed asynchronously, for example by sending a message to it, or by explicitly waiting for it using a construct such as when
in E, then there is no difficulty in delaying until the future is resolved before the message can be received or the wait completes. This is the only case to be considered in purely asynchronous systems such as pure actor languages.
However, in some systems it may also be possible to attempt to immediately or synchronously access a future's value. Then there is a design choice to be made:
- the access could block the current thread or process until the future is resolved (possibly with a timeout). This is the semantics of dataflow variables in the language Oz.
- the attempted synchronous access could always signal an error, for example throwing an exception. This is the semantics of remote promises in E.[10]
- potentially, the access could succeed if the future is already resolved, but signal an error if it is not. This would have the disadvantage of introducing nondeterminism and the potential for race conditions, and seems to be an uncommon design choice.
As an example of the first possibility, in C++11, a thread that needs the value of a future can block until it is available by calling the wait()
or get()
member functions. A timeout can also be specified on the wait using the wait_for()
or wait_until()
member functions to avoid indefinite blocking. If the future arose from a call to std::async
then a blocking wait (without a timeout) may cause synchronous invocation of the function to compute the result on the waiting thread.
Related constructs
[edit]Futures are a particular case of the synchronization primitive "events," which can be completed only once. In general, events can be reset to initial empty state and, thus, completed as many times as desired.[11]
An I-var (as in the language Id) is a future with blocking semantics as defined above. An I-structure is a data structure containing I-vars. A related synchronization construct that can be set multiple times with different values is called an M-var. M-vars support atomic operations to take or put the current value, where taking the value also sets the M-var back to its initial empty state.[12]
A concurrent logic variable [citation needed] is similar to a future, but is updated by unification, in the same way as logic variables in logic programming. Thus it can be bound more than once to unifiable values, but cannot be set back to an empty or unresolved state. The dataflow variables of Oz act as concurrent logic variables, and also have blocking semantics as mentioned above.
A concurrent constraint variable is a generalization of concurrent logic variables to support constraint logic programming: the constraint may be narrowed multiple times, indicating smaller sets of possible values. Typically there is a way to specify a thunk that should run whenever the constraint is narrowed further; this is needed to support constraint propagation.
Relations between the expressiveness of different forms of future
[edit]Eager thread-specific futures can be straightforwardly implemented in non-thread-specific futures, by creating a thread to calculate the value at the same time as creating the future. In this case it is desirable to return a read-only view to the client, so that only the newly created thread is able to resolve this future.
To implement implicit lazy thread-specific futures (as provided by Alice ML, for example) in terms in non-thread-specific futures, needs a mechanism to determine when the future's value is first needed (for example, the WaitNeeded
construct in Oz[13]). If all values are objects, then the ability to implement transparent forwarding objects is sufficient, since the first message sent to the forwarder indicates that the future's value is needed.
Non-thread-specific futures can be implemented in thread-specific futures, assuming that the system supports message passing, by having the resolving thread send a message to the future's own thread. However, this can be viewed as unneeded complexity. In programming languages based on threads, the most expressive approach seems to be to provide a mix of non-thread-specific futures, read-only views, and either a WaitNeeded construct, or support for transparent forwarding.
Evaluation strategy
[edit]The evaluation strategy of futures, which may be termed call by future, is non-deterministic: the value of a future will be evaluated at some time between when the future is created and when its value is used, but the precise time is not determined beforehand and can change from run to run. The computation can start as soon as the future is created (eager evaluation) or only when the value is actually needed (lazy evaluation), and may be suspended part-way through, or executed in one run. Once the value of a future is assigned, it is not recomputed on future accesses; this is like the memoization used in call by need.
A lazy future is a future that deterministically has lazy evaluation semantics: the computation of the future's value starts when the value is first needed, as in call by need. Lazy futures are of use in languages which evaluation strategy is by default not lazy. For example, in C++11 such lazy futures can be created by passing the std::launch::deferred
launch policy to std::async
, along with the function to compute the value.
Semantics of futures in the actor model
[edit]In the actor model, an expression of the form future <Expression>
is defined by how it responds to an Eval
message with environment E and customer C as follows: The future expression responds to the Eval
message by sending the customer C a newly created actor F (the proxy for the response of evaluating <Expression>
) as a return value concurrently with sending <Expression>
an Eval
message with environment E and customer C. The default behavior of F is as follows:
- When F receives a request R, then it checks to see if it has already received a response (that can either be a return value or a thrown exception) from evaluating
<Expression>
proceeding as follows:- If it already has a response V, then
- If V is a return value, then it is sent the request R.
- If V is an exception, then it is thrown to the customer of the request R.
- If it does not already have a response, then R is stored in the queue of requests inside the F.
- If it already has a response V, then
- When F receives the response V from evaluating
<Expression>
, then V is stored in F and- If V is a return value, then all of the queued requests are sent to V.
- If V is an exception, then it is thrown to the customer of each of the queued requests.
However, some futures can deal with requests in special ways to provide greater parallelism. For example, the expression 1 + future factorial(n)
can create a new future that will behave like the number 1+factorial(n)
. This trick does not always work. For example, the following conditional expression:
if m>future factorial(n) then print("bigger") else print("smaller")
suspends until the future for factorial(n)
has responded to the request asking if m
is greater than itself.
History
[edit]The future and/or promise constructs were first implemented in programming languages such as MultiLisp and Act 1. The use of logic variables for communication in concurrent logic programming languages was quite similar to futures. These began in Prolog with Freeze and IC Prolog, and became a true concurrency primitive with Relational Language, Concurrent Prolog, guarded Horn clauses (GHC), Parlog, Strand, Vulcan, Janus, Oz-Mozart, Flow Java, and Alice ML. The single-assignment I-var from dataflow programming languages, originating in Id and included in Reppy's Concurrent ML, is much like the concurrent logic variable.
The promise pipelining technique (using futures to overcome latency) was invented by Barbara Liskov and Liuba Shrira in 1988,[6] and independently by Mark S. Miller, Dean Tribble and Rob Jellinghaus in the context of Project Xanadu circa 1989.[14]
The term promise was coined by Liskov and Shrira, although they referred to the pipelining mechanism by the name call-stream, which is now rarely used.
Both the design described in Liskov and Shrira's paper, and the implementation of promise pipelining in Xanadu, had the limit that promise values were not first-class: an argument to, or the value returned by a call or send could not directly be a promise (so the example of promise pipelining given earlier, which uses a promise for the result of one send as an argument to another, would not have been directly expressible in the call-stream design or in the Xanadu implementation). It seems that promises and call-streams were never implemented in any public release of Argus,[15] the programming language used in the Liskov and Shrira paper. Argus development stopped around 1988.[16] The Xanadu implementation of promise pipelining only became publicly available with the release of the source code for Udanax Gold[17] in 1999, and was never explained in any published document.[18] The later implementations in Joule and E support fully first-class promises and resolvers.
Several early actor languages, including the Act series,[19][20] supported both parallel message passing and pipelined message processing, but not promise pipelining. (Although it is technically possible to implement the last of these features in the first two, there is no evidence that the Act languages did so.)
After 2000, a major revival of interest in futures and promises occurred, due to their use in responsiveness of user interfaces, and in web development, due to the request–response model of message-passing. Several mainstream languages now have language support for futures and promises, most notably popularized by FutureTask
in Java 5 (announced 2004)[21] and the async/await constructions in .NET 4.5 (announced 2010, released 2012)[22][23] largely inspired by the asynchronous workflows of F#,[24] which dates to 2007.[25] This has subsequently been adopted by other languages, notably Dart (2014),[26] Python (2015),[27] Hack (HHVM), and drafts of ECMAScript 7 (JavaScript), Scala, and C++ (2011).
List of implementations
[edit]Some programming languages are supporting futures, promises, concurrent logic variables, dataflow variables, or I-vars, either by direct language support or in the standard library.
List of concepts related to futures and promises by programming language
[edit]- ABCL/f[28]
- Alice ML
- AmbientTalk (including first-class resolvers and read-only promises)
- C++, starting with C++11: std::future and std::promise
- Compositional C++
- Crystal (programming language)
- Dart (with Future/Completer classes[29] and the keywords await and async[26])
- Elm (programming language) via the Task module[30]
- Glasgow Haskell (I-vars and M-vars only)
- Id (I-vars and M-vars only)
- Io[31]
- Java via
java.util.concurrent.Future
orjava.util.concurrent.CompletableFuture
- JavaScript as of ECMAScript 2015,[32] and via the keywords
async
andawait
since ECMAScript 2017[33] - Lucid (dataflow only)
- Some Lisps
- .NET via Tasks
- Kotlin, however
kotlin.native.concurrent.Future
is only usually used when writing Kotlin that is intended to run natively[35] - Nim
- Oxygene
- Oz version 3[36]
- Python concurrent.futures, since 3.2,[37] as proposed by the PEP 3148, and Python 3.5 added async and await[38]
- R (promises for lazy evaluation, still single threaded)
- Racket[39]
- Raku[40]
- Rust (usually achieved via
.await
)[41] - Scala via scala.concurrent package
- Scheme
- Squeak Smalltalk
- Strand
- Swift (only via third-party libraries)
- Visual Basic[clarification needed] 11 (via the keywords Async and Await)[23]
Languages also supporting promise pipelining include:
List of library-based implementations of futures
[edit]- For Common Lisp:
- For C++:
- For C# and other .NET languages: The Parallel Extensions library
- For Groovy: GPars[54]
- For JavaScript:
- Cujo.js'[55] when.js[56] provides promises conforming to the Promises/A+[57] 1.1 specification
- The Dojo Toolkit supplies promises[58] and Twisted style deferreds
- MochiKit[59] inspired by Twisted's Deferreds
- jQuery's Deferred Object is based on the CommonJS Promises/A design.
- AngularJS[60]
- node-promise[61]
- Q, by Kris Kowal, conforms to Promises/A+ 1.1[62]
- RSVP.js, conforms to Promises/A+ 1.1[63]
- YUI's[64] promise class[65] conforms to the Promises/A+ 1.0 specification.
- Bluebird, by Petka Antonov[66]
- The Closure Library's promise package conforms to the Promises/A+ specification.
- See Promise/A+'s list for more implementations based on the Promise/A+ design.
- For Java:
- For Lua:
- The cqueues [1] module contains a Promise API.
- For Objective-C: MAFuture,[69][70] RXPromise,[71] ObjC-CollapsingFutures,[72] PromiseKit,[73] objc-promise,[74] OAPromise,[75]
- For OCaml: Lazy module implements lazy explicit futures[76]
- For Perl: Future,[77] Promises,[78] Reflex,[79] Promise::ES6,[80] and Promise::XS[81]
- For PHP: React/Promise[82]
- For Python:
- For R:
- For Ruby:
- For Rust:
- futures-rs[93]
- For Scala:
- Twitter's util library[94]
- For Swift:
- Async framework, implements C#-style
async
/non-blockingawait
[95] - FutureKit,[96] implements a version for Apple GCD[97]
- FutureLib, pure Swift 2 library implementing Scala-style futures and promises with TPL-style cancellation[98]
- Deferred, pure Swift library inspired by OCaml's Deferred[99]
- BrightFutures[100]
- SwiftCoroutine[101]
- Async framework, implements C#-style
- For Tcl: tcl-promise[102]
Coroutines
[edit]Futures can be implemented in coroutines[27] or generators,[103] resulting in the same evaluation strategy (e.g., cooperative multitasking or lazy evaluation).
Channels
[edit]Futures can easily be implemented in channels: a future is a one-element channel, and a promise is a process that sends to the channel, fulfilling the future.[104][105] This allows futures to be implemented in concurrent programming languages with support for channels, such as CSP and Go. The resulting futures are explicit, as they must be accessed by reading from the channel, rather than only evaluation.
See also
[edit]- Fiber (computer science)
- Futex
- Pyramid of doom (programming), a design antipattern avoided by promises
References
[edit]- ^ Friedman, Daniel; David Wise (1976). The Impact of Applicative Programming on Multiprocessing. International Conference on Parallel Processing. pp. 263–272.
Preliminary version of: Friedman, Daniel; Wise, David (April 1978). "Aspects of Applicative Programming for Parallel Processing". IEEE Transactions on Computers. C-27 (4): 289–296. CiteSeerX 10.1.1.295.9692. doi:10.1109/tc.1978.1675100. S2CID 16333366. - ^ Hibbard, Peter (1976). Parallel Processing Facilities. New Directions in Algorithmic Languages, (ed.) Stephen A. Schuman, IRIA, 1976.
- ^ Henry Baker; Carl Hewitt (August 1977). The Incremental Garbage Collection of Processes. Proceedings of the Symposium on Artificial Intelligence Programming Languages. ACM SIGPLAN Notices 12, 8. pp. 55–59. Archived from the original on 4 July 2008. Retrieved 13 February 2015.
- ^ Promise Pipelining at erights.org
- ^ Promise Pipelining on the C2 wiki
- ^ a b Barbara Liskov; Liuba Shrira (1988). "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. pp. 260–267. doi:10.1145/53990.54016. ISBN 0-89791-269-1. Also published in ACM SIGPLAN Notices 23(7).
- ^ Robust promises with Dojo deferred, Site Pen, 3 May 2010
- ^ a b "Promise", Alice Manual, DE: Uni-SB, archived from the original on 8 October 2008, retrieved 21 March 2007
- ^ a b "Future", Alice manual, DE: Uni-SB, archived from the original on 6 October 2008, retrieved 21 March 2007
- ^ Promise, E rights
- ^ 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, archived from the original on 18 April 2009
- ^ WaitNeeded, Mozart Oz, archived from the original on 17 May 2013, retrieved 21 March 2007
- ^ Promise, Sunless Sea, archived from the original on 23 October 2007
- ^ Argus, MIT
- ^ Liskov, Barbara (26 January 2021), Distributed computing and Argus, Oral history, IEEE GHN
- ^ Gold, Udanax, archived from the original on 11 October 2008
- ^ Pipeline, E rights
- ^ Henry Lieberman (June 1981). "A Preview of Act 1". MIT AI Memo 625.
- ^ Henry Lieberman (June 1981). "Thinking About Lots of Things at Once without Getting Confused: Parallelism in Act 1". MIT AI Memo 626.
- ^ Goetz, Brian (23 November 2004). "Concurrency in JDK 5.0". IBM.
- ^ a b "Async in 4.5: Worth the Await – .NET Blog – Site Home – MSDN Blogs". Blogs.msdn.com. Retrieved 13 May 2014.
- ^ a b c "Asynchronous Programming with Async and Await (C# and Visual Basic)". Msdn.microsoft.com. Retrieved 13 May 2014.
- ^ Tomas Petricek (29 October 2010). "Asynchronous C# and F# (I.): Simultaneous introduction".
- ^ Don Syme; Tomas Petricek; Dmitry Lomov (21 October 2010). "The F# Asynchronous Programming Model, PADL 2011".
- ^ a b Gilad Bracha (October 2014). "Dart Language Asynchrony Support: Phase 1".
- ^ a b "PEP 0492 – Coroutines with async and await syntax".
- ^ Kenjiro Taura; Satoshi Matsuoka; Akinori Yonezawa (1994). "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. pp. 275–292. CiteSeerX 10.1.1.23.1161.
- ^ "Dart SDK dart async Completer".
- ^ "Task".
- ^ Steve Dekorte (2005). "Io, The Programming Language".
- ^ "Using promises". Mozilla Developer Network. Retrieved 23 February 2021.
- ^ "Making asynchronous programming easier with async and await". Mozilla Developer Network. Retrieved 23 February 2021.
- ^ Rich Hickey (2009). "changes.txt at 1.1.x from richhickey's clojure". GitHub.
- ^ "Future – Kotlin Programming Language".
- ^ Seif Haridi; Nils Franzen. "Tutorial of Oz". Mozart Global User Library. Archived from the original on 14 May 2011. Retrieved 12 April 2011.
- ^ Python 3.2 Release
- ^ Python 3.5 Release
- ^ "Parallelism with Futures". PLT. Retrieved 2 March 2012.
- ^ "class Promise". raku.org. Retrieved 19 August 2022.
- ^ "Future in std::future - Rust". doc.rust-lang.org. Retrieved 16 December 2023.
- ^ Common Lisp Blackbird
- ^ Common Lisp Eager Future2
- ^ Lisp in parallel – A parallel programming library for Common Lisp
- ^ Common Lisp PCall
- ^ "Chapter 30. Thread 4.0.0". Retrieved 26 June 2013.
- ^ "Dlib C++ Library #thread_pool". Retrieved 26 June 2013.
- ^ "GitHub – facebook/folly: An open-source C++ library developed and used at Facebook". GitHub. 8 January 2019.
- ^ "HPX". 10 February 2019.
- ^ "Threads Slides of POCO" (PDF).
- ^ "QtCore 5.0: QFuture Class". Qt Project. Archived from the original on 1 June 2013. Retrieved 26 June 2013.
- ^ "Seastar". Seastar project. Retrieved 22 August 2016.
- ^ "stlab is the ongoing work of what was Adobe's Software Technology Lab. The Adobe Source Libraries (ASL), Platform Libraries, and new stlab libraries are hosted on github". 31 January 2021.
- ^ Groovy GPars Archived 12 January 2013 at the Wayback Machine
- ^ Cujo.js
- ^ JavaScript when.js
- ^ Promises/A+ specification
- ^ promises
- ^ JavaScript MochKit.Async
- ^ JavaScript Angularjs
- ^ JavaScript node-promise
- ^ "JavaScript Q". Archived from the original on 31 December 2018. Retrieved 8 April 2013.
- ^ JavaScript RSVP.js
- ^ YUI JavaScript class library
- ^ YUI JavaScript promise class
- ^ JavaScript Bluebird
- ^ Java JDeferred
- ^ Java ParSeq
- ^ Objective-C MAFuture GitHub
- ^ Objective-C MAFuture mikeash.com
- ^ Objective-C RXPromise
- ^ ObjC-CollapsingFutures
- ^ Objective-C PromiseKit
- ^ Objective-C objc-promise
- ^ Objective-C OAPromise
- ^ OCaml Lazy
- ^ Perl Future
- ^ Perl Promises
- ^ Perl Reflex
- ^ Perl Promise::ES6
- ^ "Promise::XS – Fast promises in Perl – metacpan.org". metacpan.org. Retrieved 14 February 2021.
- ^ PHP React/Promise
- ^ Python built-in implementation
- ^ pythonfutures
- ^ "Twisted Deferreds". Archived from the original on 6 August 2020. Retrieved 29 April 2010.
- ^ R package future
- ^ future
- ^ Concurrent Ruby
- ^ Ruby Promise gem
- ^ Ruby libuv
- ^ "Ruby Celluloid gem". Archived from the original on 8 May 2013. Retrieved 19 February 2022.
- ^ Ruby future-resource
- ^ futures-rs crate
- ^ Twitter's util library
- ^ "Swift Async". Archived from the original on 31 December 2018. Retrieved 23 June 2014.
- ^ Swift FutureKit
- ^ Swift Apple GCD
- ^ Swift FutureLib
- ^ bignerdranch/Deferred
- ^ Thomvis/BrightFutures
- ^ belozierov/SwiftCoroutine
- ^ tcl-promise
- ^ Does async/await solve a real problem?
- ^ "Go language patterns Futures". Archived from the original on 4 December 2020. Retrieved 9 February 2014.
- ^ "Go Language Patterns". Archived from the original on 11 November 2020. Retrieved 9 February 2014.