[Newbies] Callback
Benjamin Schroeder
benschroeder at acm.org
Thu Oct 9 14:08:18 UTC 2008
On Oct 9, 2008, at 9:54 AM, xyz 42 wrote:
> Hello! I want to create a callback that will call my method after,
> say, 10 minutes. How can I do it in squeak?
You could try something like
[10 minutes asDelay wait. self doSomething] fork
Breaking the above down,
the square brackets indicate a block, the same kind of thing used in
conditionals, select: messages, etc.
"fork" tells the block to start running on a new thread, so
statements after
this one can execute without waiting the ten minutes.
"10 minutes asDelay" creates a Delay object, and sending "wait" to it
waits for the appropriate amount of time.
Going further, "10 minutes" creates a Duration, and sending "asDelay"
to
it creates a Delay that is set up with the same amount of time as the
Duration.
There are other ways to create Delays and Durations - check out the
class side of Delay or Duration in a browser, as well as the
"converting" category of methods for Number. (This is where the
"minutes" message above comes from.)
Hope this helps,
Ben Schroeder
More information about the Beginners
mailing list