at:tutorial:actors
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
at:tutorial:actors [2007/04/01 13:05] – tvcutsem | at:tutorial:actors [2007/04/06 20:00] – added tvcutsem | ||
---|---|---|---|
Line 165: | Line 165: | ||
=== Futures === | === Futures === | ||
- | futures language | + | As you may have noticed previously, asynchronous message sends do not return any value (that is, they return '' |
+ | |||
+ | The most well-known language feature to reconcile return values with asynchronous message sends is the notion of a //future//. Futures are objects that represent return values that may not yet have been computed. Once the asynchronously invoked method has completed, the future is replaced with the actual return value, and objects that referred to the future transparently refer to the return value. | ||
+ | |||
+ | Using futures, it is possible to re-implement the previous example of requesting our calculator actor to add two numbers as follows: | ||
+ | |||
+ | < | ||
+ | def sum := calculator< | ||
+ | </ | ||
+ | |||
+ | Futures are a frequently recurring | ||
+ | |||
+ | To enable futures, it suffices to import the futures module and to enable it, as follows: | ||
+ | |||
+ | < | ||
+ | import / | ||
+ | enableFutures(true); | ||
+ | </ | ||
+ | |||
+ | The first statement imports the futures module into the current lexical scope. This enables you as a developer to use some additional language constructs exported by the futures module, as will be explained later. The second statement enables the futures behaviour, causing any asynchronous message send to return a future rather than '' | ||
=== Actor Mirrors === | === Actor Mirrors === |
at/tutorial/actors.txt · Last modified: 2020/02/05 21:26 by elisag