at:byexample
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
at:byexample [2008/08/11 20:26] – created tvcutsem | at:byexample [2009/10/08 14:11] (current) – tvcutsem | ||
---|---|---|---|
Line 7: | Line 7: | ||
Here is how to send a message to a remote object, receive a reply, and deal with the exception that the reply was not received in time: | Here is how to send a message to a remote object, receive a reply, and deal with the exception that the reply was not received in time: | ||
- | < | + | < |
import / | import / | ||
- | when: lightbulb< | + | when: lightbulb< |
- | // code to execute when the light bulb switched on | + | // code to execute when the message has been |
- | // lightStatus | + | // succesfully processed. |
+ | // reply refers to the return value of the | ||
+ | // toggleLight method. | ||
} catch: TimeoutException using: { |e| | } catch: TimeoutException using: { |e| | ||
- | // code to execute when the light bulb did not respond before 10 seconds | + | // code to execute when the light bulb did not |
- | // note: this block may be executed either because | + | // respond before 10 seconds |
- | // could not be sent or was not succesfully acknowledged, | + | // note: this block may be executed either because |
- | // carrying the reply was not received, or has not yet been received (missed the deadline) | + | // the message toggleLight |
+ | // not succesfully acknowledged, | ||
+ | // carrying the reply was not received, or has not yet | ||
+ | // been received (missed the deadline) | ||
} | } | ||
</ | </ | ||
Line 33: | Line 38: | ||
where '' | where '' | ||
- | < | + | < |
def sub := when: Type discovered: { |obj| | def sub := when: Type discovered: { |obj| | ||
- | | + | |
} | } | ||
</ | </ | ||
- | Here, '' | + | Here, '' |
The above block is triggered upon discovering one object of the appropriate (sub)type. If one wants to trigger a block every time an object of the appropriate type is discovered, execute: | The above block is triggered upon discovering one object of the appropriate (sub)type. If one wants to trigger a block every time an object of the appropriate type is discovered, execute: | ||
- | < | + | < |
whenever: Type discovered: { |obj| | whenever: Type discovered: { |obj| | ||
- | | + | |
} | } | ||
</ | </ | ||
Line 52: | Line 57: | ||
Given a far reference '' | Given a far reference '' | ||
- | < | + | < |
def sub := when: ref disconnected: | def sub := when: ref disconnected: | ||
- | | + | |
} | } | ||
</ | </ | ||
Line 60: | Line 65: | ||
And here is how to react to the object becoming available again: | And here is how to react to the object becoming available again: | ||
- | < | + | < |
def sub := when: ref reconnected: | def sub := when: ref reconnected: | ||
- | | + | |
} | } | ||
</ | </ | ||
Line 74: | Line 79: | ||
Here's how to create a lease for an object: | Here's how to create a lease for an object: | ||
- | < | + | < |
import / | import / | ||
Line 82: | Line 87: | ||
Here, '' | Here, '' | ||
- | < | + | < |
when: l expired: { | when: l expired: { | ||
- | | + | |
} | } | ||
</ | </ | ||
Line 92: | Line 97: | ||
Here's how to postpone the execution of a block of code until a certain period of time has elapsed: | Here's how to postpone the execution of a block of code until a certain period of time has elapsed: | ||
- | < | + | < |
import / | import / | ||
def sub := when: seconds(10) elapsed: { | def sub := when: seconds(10) elapsed: { | ||
- | | + | |
} | } | ||
</ | </ | ||
Line 102: | Line 107: | ||
Here, '' | Here, '' | ||
- | < | + | < |
whenever: minutes(1) elapsed: { | whenever: minutes(1) elapsed: { | ||
- | | + | |
} | } | ||
</ | </ |
at/byexample.1218479179.txt.gz · Last modified: 2008/08/11 20:28 (external edit)