How to do: something every: soOften?

Ned Konz ned at squeakland.org
Sat Dec 27 00:06:09 UTC 2003


On Friday 26 December 2003 2:03 pm, Jimmie Houchin wrote:

> I am wanting to call a method every certainTimeInterval.
>
> The other day I spent the afternoon browsing for the appropriate method
> to handle something like this. I found many different time, delay and
> event type messages but I didn't spot anything like this:
>
> Cron do: [some activity] every: someTimeInterval
>
> I may very well have overlooked what I was looking for.
>
> I can definitely put something together that works from what I saw.
>
> But is there a favored way to handle something like this in Squeak.

If you're using Morphic, you can use stepping (you can step other messages 
besides #step, and at different rates).

Look at the methods whose names contain the string 'startStepping'.

Otherwise, you can do (as Julian suggested):

[ delay := Delay forSeconds: 123456.
	[ delay wait. self doSomething ] repeat ] fork.

Remember that you should use synchronization of some sort (SharedQueues are 
the easiest to use) between threads (especially, you can't call any Morphic 
methods directly from a non-UI thread).

There is a way to communicate from background threads to Morphic, and it's 
called #addDeferredUIMessage: . I extended this with a SystemController 
subclass for the same purpose in MVC (as part of the ProcessBrowser).



More information about the Squeak-dev mailing list