Applications
Futures and promises originated inImplicit vs. explicit
Use of futures may be ''implicit'' (any use of the future automatically obtains its value, as if it were an ordinaryget
method of in 3 + ''future '' factorial(100000)
. In pure actor or object languages this problem can be solved by sending ''future '' factorial(100000)
the message + /code>, 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
The use of futures can dramatically reduce latency in distributed systems
A distributed system is a system whose components are located on different networked computers, which communicate and coordinate their actions by passing messages to one another from any system. Distributed computing is a field of computer sci ...
. For instance, futures enable ''promise pipelining'', as implemented in the languages E and Joule
The joule ( , ; symbol: J) is the unit of energy in the International System of Units (SI). It is equal to the amount of work done when a force of 1 newton displaces a mass through a distance of 1 metre in the direction of the force applied ...
, which was also called ''call-stream'' Also published in ''ACM SIGPLAN Notices'' 23(7). in the language Argus.
Consider an expression involving conventional remote procedure call
In distributed computing, a remote procedure call (RPC) is when a computer program causes a procedure (subroutine) to execute in a different address space (commonly on another computer on a shared network), which is coded as if it were a normal (l ...
s, 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
In some programming languages such as Oz, E, and AmbientTalk
AmbientTalk is an experimental Object oriented programming, object-oriented distributed programming language developed at the Programming Technology Laboratory at the Vrije Universiteit Brussel, Belgium. The language is primarily targeted at wri ...
, 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
C++11 is a version of the ISO/IEC 14882 standard for the C++ programming language. C++11 replaced the prior version of the C++ standard, called C++03, and was later replaced by C++14. The name follows the tradition of naming language versions by ...
a std::future
provides a read-only view. The value is set directly by using a std::promise
, or set to the result of a function call using std::packaged_task
or std::async
.
* In the Dojo Toolkit
Dojo Toolkit (stylized as dōjō toolkit) is an open-source modular JavaScript library (or more specifically JavaScript toolkit) designed to ease the rapid development of cross-platform, JavaScript/Ajax-based applications and web sites. It was st ...
's Deferred API as of version 1.5, a ''consumer-only promise object'' represents a read-only view.
* In Alice ML
Alice ML is a programming language designed by the Programming Systems Laboratory at Saarland University, Saarbrücken, Germany. It is a dialect of Standard ML, augmented with support for lazy evaluation, concurrency ( multithreading and dist ...
, futures provide a ''read-only view'', whereas a promise contains both a future and the ability to resolve the future
* In .NET Framework 4.0
Microsoft started development on the .NET Framework in the late 1990s originally under the name of Next Generation Windows Services (NGWS). By late 2001 the first beta versions of .NET 1.0 were released. The first version of .NET Framework was ...
System.Threading.Tasks.Task
represents a read-only view. Resolving the value can be done via System.Threading.Tasks.TaskCompletionSource
.
Support for read-only views is consistent with the principle of least privilege
In information security, computer science, and other fields, the principle of least privilege (PoLP), also known as the principle of minimal privilege (PoMP) or the principle of least authority (PoLA), requires that in a particular abstraction la ...
, 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
Some languages, such as Alice ML
Alice ML is a programming language designed by the Programming Systems Laboratory at Saarland University, Saarbrücken, Germany. It is a dialect of Standard ML, augmented with support for lazy evaluation, concurrency ( multithreading and dist ...
, define futures that are associated with a specific thread that computes the future's value. 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 computer programming, a thunk is a subroutine used to inject a calculation into another subroutine. Thunks are primarily used to delay a calculation until its result is needed, or to insert operations at the beginning or end of the other subro ...
, in the sense of a delayed computation.
Alice ML also supports futures that can be resolved by any thread, and calls these ''promises''. 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
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.
* 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
A race condition or race hazard is the condition of an electronics, software, or other system where the system's substantive behavior is dependent on the sequence or timing of other uncontrollable events. It becomes a bug when one or more of t ...
, and seems to be an uncommon design choice.
As an example of the first possibility, in C++11
C++11 is a version of the ISO/IEC 14882 standard for the C++ programming language. C++11 replaced the prior version of the C++ standard, called C++03, and was later replaced by C++14. The name follows the tradition of naming language versions by ...
, a thread that needs the value of a future can block until it is available by calling the wait()
or get()
member functions. You can also specify a timeout 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
''Futures'' are a particular case of the synchronization primitive "events
Event may refer to:
Gatherings of people
* Ceremony, an event of ritual significance, performed on a special occasion
* Convention (meeting), a gathering of individuals engaged in some common interest
* Event management, the organization of ev ...
," which can be completed only once. In general, events can be reset to initial empty state and, thus, completed as many times as you like.
An ''I-var'' (as in the language Id) is a future with blocking semantics as defined above. An ''I-structure'' is a data structure
In computer science, a data structure is a data organization, management, and storage format that is usually chosen for efficient access to data. More precisely, a data structure is a collection of data values, the relationships among them, a ...
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.
A ''concurrent logic variable'' is similar to a future, but is updated by unification, in the same way as ''logic variables'' in logic programming
Logic programming is a programming paradigm which is largely based on formal logic. Any program written in a logic programming language is a set of sentences in logical form, expressing facts and rules about some problem domain. Major logic prog ...
. 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
Constraint logic programming is a form of constraint programming, in which logic programming is extended to include concepts from constraint satisfaction. A constraint logic program is a logic program that contains constraints in the body of clau ...
: 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
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). 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
The evaluation strategy
In a programming language, an evaluation strategy is a set of rules for evaluating expressions. The term is often used to refer to the more specific notion of a ''parameter-passing strategy'' that defines the kind of value that is passed to the f ...
of futures, which may be termed ''call by future
In a programming language, an evaluation strategy is a set of rules for evaluating expressions. The term is often used to refer to the more specific notion of a ''parameter-passing strategy'' that defines the kind of value that is passed to the f ...
'', 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
In a programming language, an evaluation strategy is a set of rules for evaluating expressions. The term is often used to refer to the more specific notion of a ''parameter-passing strategy'' that defines the kind of value that is passed to the f ...
) or only when the value is actually needed (lazy evaluation
In programming language theory, lazy evaluation, or call-by-need, is an evaluation strategy which delays the evaluation of an expression until its value is needed (non-strict evaluation) and which also avoids repeated evaluations (sharing).
The b ...
), 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
In computing, memoization or memoisation is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again. Memoization ...
used in call by need
In programming language theory, lazy evaluation, or call-by-need, is an evaluation strategy which delays the evaluation of an expression until its value is needed ( non-strict evaluation) and which also avoids repeated evaluations (sharing).
Th ...
.
A 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
C++11 is a version of the ISO/IEC 14882 standard for the C++ programming language. C++11 replaced the prior version of the C++ standard, called C++03, and was later replaced by C++14. The name follows the tradition of naming language versions by ...
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
In the actor model, an expression of the form ''future''
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
) as a return value ''concurrently'' with sending
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
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''.
* When ''F'' receives the response ''V'' from evaluating
, 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
The ''future'' and/or ''promise'' constructs were first implemented in programming languages such as MultiLisp
MultiLisp is a functional programming language, a dialect of the language Lisp, and of its dialect Scheme, extended with constructs for parallel computing execution and shared memory. These extensions involve side effects, rendering MultiLisp ...
and Act 1. The use of logic variables for communication in concurrent
Concurrent means happening at the same time. Concurrency, concurrent, or concurrence may refer to:
Law
* Concurrence, in jurisprudence, the need to prove both ''actus reus'' and ''mens rea''
* Concurring opinion (also called a "concurrence"), a ...
logic programming
Logic programming is a programming paradigm which is largely based on formal logic. Any program written in a logic programming language is a set of sentences in logical form, expressing facts and rules about some problem domain. Major logic prog ...
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
Prolog is a logic programming language associated with artificial intelligence and computational linguistics.
Prolog has its roots in first-order logic, a formal logic, and unlike many other programming languages, Prolog is intended primarily ...
, guarded Horn clause In mathematical logic and logic programming, a Horn clause is a logical formula of a particular rule-like form which gives it useful properties for use in logic programming, formal specification, and model theory. Horn clauses are named for the log ...
s (GHC), Parlog Parlog is a logic programming language designed for efficient utilization of parallel computer architectures. Its semantics is based on first order predicate logic. It expresses concurrency, interprocess communication, indeterminacy and synchroniz ...
, Strand
Strand may refer to:
Topography
*The flat area of land bordering a body of water, a:
** Beach
** Shoreline
* Strand swamp, a type of swamp habitat in Florida
Places Africa
* Strand, Western Cape, a seaside town in South Africa
* Strand Street ...
, Vulcan
Vulcan may refer to:
Mythology
* Vulcan (mythology), the god of fire, volcanoes, metalworking, and the forge in Roman mythology
Arts, entertainment and media Film and television
* Vulcan (''Star Trek''), name of a fictional race and their home p ...
, Janus
In ancient Roman religion and myth, Janus ( ; la, Ianvs ) is the god of beginnings, gates, transitions, time, duality, doorways, passages, frames, and endings. He is usually depicted as having two faces. The month of January is named for Janu ...
, Oz-Mozart, Flow Java, and Alice ML
Alice ML is a programming language designed by the Programming Systems Laboratory at Saarland University, Saarbrücken, Germany. It is a dialect of Standard ML, augmented with support for lazy evaluation, concurrency ( multithreading and dist ...
. The single-assignment ''I-var'' from dataflow programming
In computer programming, dataflow programming is a programming paradigm that models a program as a directed graph of the data flowing between operations, thus implementing dataflow principles and architecture. Dataflow programming languages share ...
languages, originating in Id and included in Reppy's ''Concurrent ML
Concurrent ML (CML) is a concurrent extension of the Standard ML programming language characterized by its ability to allow programmers to create composable communication abstractions that are first-class rather than built into the language. ...
'', is much like the concurrent logic variable.
The promise pipelining technique (using futures to overcome latency) was invented by Barbara Liskov
Barbara Liskov (born November 7, 1939 as Barbara Jane Huberman) is an American computer scientist who has made pioneering contributions to programming languages and distributed computing. Her notable work includes the development of the Liskov ...
and Liuba Shrira
Liuba Shrira is a professor of computer science at Brandeis University, whose research interests primarily involve distributed systems.
Liuba Shrira received her PhD from Technion. She is affiliated with the MIT Computer Science and Artificial ...
in 1988, and independently by Mark S. Miller
Mark S. Miller is an American computer scientist. He is known for his work as one of the participants in the 1979 hypertext project known as Project Xanadu; for inventing Miller columns; and the open-source coordinator of the E programming lan ...
, Dean Tribble and Rob Jellinghaus in the context of Project Xanadu
Project Xanadu ( ) was the first hypertext project, founded in 1960 by Ted Nelson. Administrators of Project Xanadu have declared it superior to the World Wide Web, with the mission statement: "Today's popular software simulates paper. The World ...
circa 1989.
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, the programming language used in the Liskov and Shrira paper. Argus development stopped around 1988. The Xanadu implementation of promise pipelining only became publicly available with the release of the source code for Udanax Gold in 1999, and was never explained in any published document. The later implementations in Joule and E support fully first-class promises and resolvers.
Several early actor languages, including the Act series, 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
Responsiveness as a concept of computer science refers to the specific ability of a system or functional unit to complete assigned tasks within a given time. For example, it would refer to the ability of an artificial intelligence system to unde ...
of user interfaces, and in web development
Web development is the work involved in developing a website for the Internet (World Wide Web) or an intranet (a private network). Web development can range from developing a simple single static page of plain text to complex web applications ...
, due to the request–response
In computer science, request–response or request–reply is one of the basic methods computers use to communicate with each other in a network, in which the first computer sends a ''request'' for some data and the second ''responds'' to the requ ...
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) and the async/await
In computer programming, the async/await pattern is a syntactic feature of many programming languages that allows an asynchronous, non-blocking function to be structured in a way similar to an ordinary synchronous function. It is semantically rel ...
constructions in .NET 4.5 (announced 2010, released 2012) largely inspired by the ''asynchronous workflows'' of F#, which dates to 2007. This has subsequently been adopted by other languages, notably Dart (2014), Python (2015), Hack (HHVM), and drafts of ECMAScript 7 (JavaScript), Scala, and C++ (2011).
List of implementations
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
* ABCL/f
* Alice ML
Alice ML is a programming language designed by the Programming Systems Laboratory at Saarland University, Saarbrücken, Germany. It is a dialect of Standard ML, augmented with support for lazy evaluation, concurrency ( multithreading and dist ...
* AmbientTalk
AmbientTalk is an experimental Object oriented programming, object-oriented distributed programming language developed at the Programming Technology Laboratory at the Vrije Universiteit Brussel, Belgium. The language is primarily targeted at wri ...
(including first-class resolvers and read-only promises)
* C++
C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
, starting with C++11
C++11 is a version of the ISO/IEC 14882 standard for the C++ programming language. C++11 replaced the prior version of the C++ standard, called C++03, and was later replaced by C++14. The name follows the tradition of naming language versions by ...
: std::future and std::promise
** Compositional C++
* Crystal (programming language)
Crystal is a general-purpose, object-oriented programming language, designed and developed by Ary Borenszweig, Juan Wajnerman, Brian Cardiff and more than 300 contributors. With syntax inspired by the language Ruby, it is a compiled language ...
* Dart
Dart or DART may refer to:
* Dart, the equipment in the game of darts
Arts, entertainment and media
* Dart (comics), an Image Comics superhero
* Dart, a character from ''G.I. Joe''
* Dart, a ''Thomas & Friends'' railway engine character
* Dar ...
(with ''Future''/''Completer'' classes and the keywords ''await'' and ''async'')
* Elm (programming language)
Elm is a Domain-specific language, domain-specific programming language for Declarative programming, declaratively creating web browser-based graphical user interfaces. Elm is purely functional programming, purely functional, and is developed wi ...
via the ''Task'' module
* Glasgow Haskell
Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lan ...
(I-vars and M-vars only)
* Id (I-vars and M-vars only)
* Io
* Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
via or
* JavaScript
JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
as of ECMAScript
ECMAScript (; ES) is a JavaScript standard intended to ensure the interoperability of web pages across different browsers. It is standardized by Ecma International in the documenECMA-262
ECMAScript is commonly used for client-side scripting o ...
2015, and via the keywords async
and await
since ECMAScript 2017
* Lucid
LUCID (Langton Ultimate Cosmic ray Intensity Detector) is a cosmic ray detector built by Surrey Satellite Technology Ltd and designed at Simon Langton Grammar School for Boys, in Canterbury, England. Its main purpose is to monitor cosmic rays usi ...
(dataflow only)
* Some Lisps
** Clojure
Clojure (, like ''closure'') is a dynamic and functional dialect of the Lisp programming language on the Java platform. Like other Lisp dialects, Clojure treats code as data and has a Lisp macro system. The current development process is comm ...
** MultiLisp
MultiLisp is a functional programming language, a dialect of the language Lisp, and of its dialect Scheme, extended with constructs for parallel computing execution and shared memory. These extensions involve side effects, rendering MultiLisp ...
* .NET via ''Task''s
** C#, since .NET Framework 4.5, via the keywords async
and await
* Kotlin, however kotlin.native.concurrent.Future
is only usually used when writing Kotlin that is intended to run natively
* Nim
* Oxygene
* Oz version 3
* Python
Python may refer to:
Snakes
* Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia
** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia
* Python (mythology), a mythical serpent
Computing
* Python (pro ...
br>concurrent.futures
since 3.2, as proposed by th
PEP 3148
and Python 3.5 added async and await
* R (promises for lazy evaluation, still single threaded)
* Racket
* Raku
* Rust
Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
(usually achieved via .await
)
* Scala vi
scala.concurrent package
* Scheme A scheme is a systematic plan for the implementation of a certain idea.
Scheme or schemer may refer to:
Arts and entertainment
* ''The Scheme'' (TV series), a BBC Scotland documentary series
* The Scheme (band), an English pop band
* ''The Schem ...
* Squeak
Squeak is an object-oriented, class-based, and reflective programming language. It was derived from Smalltalk-80 by a group that included some of Smalltalk-80's original developers, initially at Apple Computer, then at Walt Disney Imagineering, ...
Smalltalk
Smalltalk is an object-oriented, dynamically typed reflective programming language. It was designed and created in part for educational use, specifically for constructionist learning, at the Learning Research Group (LRG) of Xerox PARC by Alan Ka ...
* Strand
Strand may refer to:
Topography
*The flat area of land bordering a body of water, a:
** Beach
** Shoreline
* Strand swamp, a type of swamp habitat in Florida
Places Africa
* Strand, Western Cape, a seaside town in South Africa
* Strand Street ...
* Swift
Swift or SWIFT most commonly refers to:
* SWIFT, an international organization facilitating transactions between banks
** SWIFT code
* Swift (programming language)
* Swift (bird), a family of birds
It may also refer to:
Organizations
* SWIFT, ...
(only via third-party libraries)
* Visual Basic Visual Basic is a name for a family of programming languages from Microsoft. It may refer to:
* Visual Basic .NET (now simply referred to as "Visual Basic"), the current version of Visual Basic launched in 2002 which runs on .NET
* Visual Basic (cl ...
11 (via the keywords ''Async'' and ''Await'')
Languages also supporting promise pipelining include:
* E
* Joule
The joule ( , ; symbol: J) is the unit of energy in the International System of Units (SI). It is equal to the amount of work done when a force of 1 newton displaces a mass through a distance of 1 metre in the direction of the force applied ...
List of non-standard, library based implementations of futures
* For Common Lisp
Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived fro ...
:
** Blackbird
** Eager Future2
** lparallel
** PCall
* For C++:
** Boost library
Boost is a set of libraries for the C++ programming language that provides support for tasks and structures such as linear algebra, pseudorandom number generation, multithreading, image processing, regular expressions, and unit testing. It conta ...
** Dlib
Dlib is a general purpose cross-platform software library written in the programming language C++. Its design is heavily influenced by ideas from design by contract and component-based software engineering. Thus it is, first and foremost, a set ...
** Folly
** HPX
** POCO C++ Libraries
The POrtable COmponents (POCO) C++ Libraries are computer software, a set of class libraries for developing computer network-centric, portable applications in the programming language C++. The libraries cover functions such as threads, thread syn ...
(Active Results)
** Qt
** Seastar
** stlab
* For C# and other .NET languages: The Parallel Extensions
Parallel Extensions was the development name for a managed concurrency library developed by a collaboration between Microsoft Research and the CLR team at Microsoft. The library was released in version 4.0 of the .NET Framework. It is composed ...
library
* For Groovy
''Groovy'' (or, less commonly, ''groovie'' or ''groovey'') is a slang colloquialism popular during the 1950s, '60s and '70s. It is roughly synonymous with words such as "excellent", "fashionable", or "amazing", depending on context.
History
The ...
: GPars
* For JavaScript
JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
:
** Cujo.js' when.js provides promises conforming to the Promises/A+ 1.1 specification
** The Dojo Toolkit
Dojo Toolkit (stylized as dōjō toolkit) is an open-source modular JavaScript library (or more specifically JavaScript toolkit) designed to ease the rapid development of cross-platform, JavaScript/Ajax-based applications and web sites. It was st ...
supplies promises and Twisted style deferreds
** MochiKit
MochiKit is a light-weight JavaScript library written and maintained by Bob Ippolito.
Inspired by the Python networking framework, Twisted, it uses the concept of deferred execution to allow asynchronous behaviour. This has made it useful in ...
inspired by Twisted's Deferreds
*
jQuery's
/api.jquery.com/category/deferred-object/ Deferred Objectis based on th
CommonJS Promises/A
design.
** AngularJS
** node
In general, a node is a localized swelling (a "knot") or a point of intersection (a vertex).
Node may refer to:
In mathematics
*Vertex (graph theory), a vertex in a mathematical graph
*Vertex (geometry), a point where two or more curves, lines, ...
-promise
** Q, by Kris Kowal, conforms to Promises/A+ 1.1
** RSVP.js, conforms to Promises/A+ 1.1
** YUI's promise class conforms to the Promises/A+ 1.0 specification.
** Bluebird, by Petka Antonov
** The Closure Library'
promise
package conforms to the Promises/A+ specification.
** Se
Promise/A+'s
list for more implementations based on the Promise/A+ design.
* For Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
:
** JDeferred, provides deferred-promise API and behavior similar to JQuery
jQuery is a JavaScript library designed to simplify HTML DOM tree traversal and manipulation, as well as event handling, CSS animation, and Ajax. It is free, open-source software using the permissive MIT License. As of Aug 2022, jQuery is used ...
.Deferred object
** ParSeq provides task-promise API ideal for asynchronous pipelining and branching, maintained by LinkedIn
LinkedIn () is an American business and employment-oriented online service that operates via websites and mobile apps. Launched on May 5, 2003, the platform is primarily used for professional networking and career development, and allows job se ...
* For Lua
Lua or LUA may refer to:
Science and technology
* Lua (programming language)
* Latvia University of Agriculture
* Last universal ancestor, in evolution
Ethnicity and language
* Lua people, of Laos
* Lawa people, of Thailand sometimes referred t ...
:
** The cqueue
module contains a Promise API.
* For Objective-C
Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTS ...
: MAFuture, RXPromise, ObjC-CollapsingFutures, PromiseKit, objc-promise, OAPromise,
* For OCaml
OCaml ( , formerly Objective Caml) is a general-purpose programming language, general-purpose, multi-paradigm programming language which extends the Caml dialect of ML (programming language), ML with object-oriented programming, object-oriented ...
: Lazy module implements lazy explicit futures
* For Perl
Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offici ...
: Future, Promises, Reflex, Promise::ES6, and Promise::XS
* For PHP
PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group ...
: React/Promise
* For Python
Python may refer to:
Snakes
* Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia
** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia
* Python (mythology), a mythical serpent
Computing
* Python (pro ...
:
** Built-in implementation
** pythonfutures
** Twisted's Deferreds
* For R:
** future, implements an extendable future API with lazy and eager synchronous and (multicore or distributed) asynchronous futures
* For Ruby
A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sa ...
:
** Concurrent Ruby
** Promise gem
** libuv gem, implements promises
** Celluloid gem, implements futures
** future-resource
* For Rust
Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
:
** futures-rs
* For Scala:
** Twitter's util library
* For Swift
Swift or SWIFT most commonly refers to:
* SWIFT, an international organization facilitating transactions between banks
** SWIFT code
* Swift (programming language)
* Swift (bird), a family of birds
It may also refer to:
Organizations
* SWIFT, ...
:
** Async framework, implements C#-style async
/non-blocking await
** FutureKit, implements a version for Apple GCD
** FutureLib, pure Swift 2 library implementing Scala-style futures and promises with TPL-style cancellation
** Deferred, pure Swift library inspired by OCaml's Deferred
** BrightFutures
** SwiftCoroutine
* For Tcl
TCL or Tcl or TCLs may refer to:
Business
* TCL Technology, a Chinese consumer electronics and appliance company
**TCL Electronics, a subsidiary of TCL Technology
* Texas Collegiate League, a collegiate baseball league
* Trade Centre Limited ...
: tcl-promise
Coroutines
Futures can be implemented in coroutine
Coroutines are computer program components that generalize subroutines for non-preemptive multitasking, by allowing execution to be suspended and resumed. Coroutines are well-suited for implementing familiar program components such as cooperative ...
s or generators, resulting in the same evaluation strategy (e.g., cooperative multitasking or lazy evaluation).
Channels
Futures can easily be implemented in channels
Channel, channels, channeling, etc., may refer to:
Geography
* Channel (geography), in physical geography, a landform consisting of the outline (banks) of the path of a narrow body of water.
Australia
* Channel Country, region of outback Austral ...
: a future is a one-element channel, and a promise is a process that sends to the channel, fulfilling the future.Go Language Patterns
/ref> 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
* Fiber (computer science)
In computer science, a fiber is a particularly lightweight thread of execution.
Like threads, fibers share address space. However, fibers use cooperative multitasking while threads use preemptive multitasking. Threads often depend on the kern ...
* Futex
In computing, a futex (short for "fast userspace mutex") is a kernel system call that programmers can use to implement basic locking, or as a building block for higher-level locking abstractions such as semaphores and POSIX mutexes or condition ...
* Pyramid of doom (programming)
In computer programming, the pyramid of doom is a common problem that arises when a program uses many levels of nested indentation to control access to a function. It is commonly seen when checking for null pointers or handling callbacks. Two ex ...
, a design antipattern avoided by promises
References
External links
Concurrency patterns presentation
given a
scaleconf
Future Value
an
Promise Pipelining
at the Portland Pattern Repository
The Portland Pattern Repository (PPR) is a repository for computer programming software design patterns. It was accompanied by a companion website, WikiWikiWeb, which was the world's first wiki. The repository has an emphasis on Extreme Programmin ...
Easy Threading with Futures
in Python
Python may refer to:
Snakes
* Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia
** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia
* Python (mythology), a mythical serpent
Computing
* Python (pro ...
{{DEFAULTSORT:Futures and promises
Inter-process communication
Actor model (computer science)