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/07/18 10:43] – elisag | at:tutorial:actors [2008/08/01 14:44] – * tvcutsem | ||
---|---|---|---|
Line 26: | Line 26: | ||
}; | }; | ||
}; | }; | ||
- | >>< | + | >>< |
</ | </ | ||
Line 112: | Line 112: | ||
}; | }; | ||
}; | }; | ||
- | >>< | + | >>< |
</ | </ | ||
Line 196: | Line 196: | ||
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 '' | 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 '' | ||
+ | |||
+ | More information pertaining to the API of the futures language module can be found in the [[: | ||
==== Working with Unresolved Futures ==== | ==== Working with Unresolved Futures ==== | ||
- | We have yet to describe what objects can do with futures that are // | + | We have described a future as a placeholder for the return value of an asynchronous message send which is eventually // |
- | Blocking a thread on a future can be a major source of deadlocks, like any form of blocking, of course. In the actor paradigm where communication between actors should remain strictly asynchronous, | + | Blocking a thread on a future can be a major source of deadlocks, like any form of blocking. In the actor paradigm where communication between actors should remain strictly asynchronous, |
- | The solution proposed in the [[http:// | + | The solution proposed in the [[http:// |
- | < | + | As an example |
- | 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. | + | < |
+ | def booleanFuture := remoteObject< | ||
+ | booleanFuture< | ||
+ | | ||
+ | } ifFalse: { | ||
+ | ... | ||
+ | } | ||
+ | </ | ||
- | AmbientTalk only allows one method to be synchronously invoked on a future, the '' | + | In this example, the message |
==== Working with Resolved Futures ==== | ==== Working with Resolved Futures ==== | ||
+ | |||
+ | 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. | ||
+ | |||
+ | <note important> | ||
+ | AmbientTalk only allows one method to be synchronously invoked on a future, the '' | ||
+ | </ | ||
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: | 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: | ||
Line 271: | Line 286: | ||
</ | </ | ||
- | Finally, it is useful to know that '' | + | Finally, it is useful to know that '' |
< | < | ||
Line 279: | Line 294: | ||
</ | </ | ||
- | When the future for ''< | + | When the future for ''< |
==== Futures and Annotated Messages ==== | ==== Futures and Annotated Messages ==== | ||
Line 318: | Line 333: | ||
An actor in AmbientTalk is primarily a //host// for regular objects. It is equipped with a message queue to receive asynchronous messages sent to one of its objects. The mirrors on these objects have corresponding meta-level operations such as '' | An actor in AmbientTalk is primarily a //host// for regular objects. It is equipped with a message queue to receive asynchronous messages sent to one of its objects. The mirrors on these objects have corresponding meta-level operations such as '' | ||
- | Some operations, such as creating and sending asynchronous messages are useful to reify at the //actor level//. With such a reification, | + | Some operations, such as creating and sending asynchronous messages are useful to reify at the //actor level//. With such a reification, |
- | Overriding the actor' | + | Overriding the actor' |
< | < | ||
- | def oldmirror := actor.install: (extend: actor with: { | + | def actor := reflectOnActor(); |
+ | def oldmirror := actor.becomeMirroredBy: (extend: actor with: { | ||
def send(msg) { | def send(msg) { | ||
log(msg); | log(msg); | ||
Line 331: | Line 347: | ||
</ | </ | ||
- | Notice that, in this example, the new metaobject protocol is an extension of the old protocol. This enables it to invoke its parent' | + | Notice that, in this example, the new metaobject protocol is an extension of the old protocol. This enables it to invoke its parent' |
+ | < | ||
For a good use case of actor mirrors, see the '' | For a good use case of actor mirrors, see the '' | ||
+ | </ | ||
Other methods that can be overridden are '' | Other methods that can be overridden are '' |
at/tutorial/actors.txt · Last modified: 2020/02/05 21:26 by elisag