at:tutorial:actors
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
at:tutorial:actors [2007/04/06 20:22] – added tvcutsem | at:tutorial:actors [2007/04/06 20:50] – tvcutsem | ||
---|---|---|---|
Line 199: | Line 199: | ||
< | < | ||
+ | |||
+ | When a future eventually becomes resolved with a value, any messages that were accumulated by the future are forwarded asynchronously to the actual return value, such that it appears as if the original object had sent the messages to the actual return value in the first place. | ||
+ | |||
+ | AmbientTalk only allows one method to be synchronously invoked on a future, the '' | ||
=== Working with Resolved Futures === | === Working with Resolved Futures === | ||
+ | As explained above, it is always correct to use asynchronous message sends to communicate with a future. Sometimes, however, we may want to perform some operation on the return value other than message sending, for example, printing it to the screen. If you print the future directly, you get the following: | ||
+ | |||
+ | < | ||
+ | def sum := calculator< | ||
+ | system.println(sum); | ||
+ | >> < | ||
+ | </ | ||
+ | |||
+ | AmbientTalk prints the future to the screen. At a later point in time, printing the future again may result in the following: | ||
+ | |||
+ | < | ||
+ | > | ||
+ | >> < | ||
+ | </ | ||
+ | |||
+ | This time, the future was printed when the return value was computed. But what if we simply want to inform the user of the actual value of '' | ||
+ | |||
+ | In AmbientTalk, | ||
+ | |||
+ | < | ||
+ | def sumFuture := calculator< | ||
+ | when: sumFuture becomes: { |sum| | ||
+ | system.println(" | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | The first argument to '' | ||
+ | |||
+ | < | ||
+ | def sumFuture := calculator< | ||
+ | when: sumFuture becomes: { |sum| | ||
+ | system.println(" | ||
+ | } catch: { |exc| | ||
+ | system.println(" | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | Or, you can specify a stripe to only catch specific exceptions: | ||
+ | |||
+ | < | ||
+ | def divFuture := calculator< | ||
+ | when: divFuture becomes: { |div| | ||
+ | system.println(" | ||
+ | } catch: DivisionByZero using: { |exc| | ||
+ | system.println(" | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | The '' | ||
+ | |||
+ | < | ||
+ | when: sumFuture becomes: { |sum| | ||
+ | system.println(" | ||
+ | }; | ||
+ | system.print(" | ||
+ | >> | ||
+ | </ | ||
+ | |||
+ | === Futures and Striped Messages === | ||
+ | |||
+ | Explain: | ||
+ | '' | ||
+ | '' | ||
+ | |||
+ | === Conditional Synchronisation with Futures === | ||
+ | explain: explicit futures using '' | ||
==== Actor Mirrors ==== | ==== Actor Mirrors ==== |
at/tutorial/actors.txt · Last modified: 2020/02/05 21:26 by elisag