How to do: something every: soOften?

Lex Spoon lex at cc.gatech.edu
Tue Dec 30 19:14:48 UTC 2003


Jimmie Houchin <jhouchin at texoma.net> wrote:


> > [ delay := Delay forSeconds: 123456.
> > 	[ delay wait. self doSomething ] repeat ] fork.
> 
> Hello Ned,
> 
> Thanks for the reply.
> 
> This is for a web app. So no Morphic.
> 
> I briefly browsed some of the stepping methods looking for ideas.
> I don't remember if I had any. :)
> 
> I will use the Delay as suggested.
> 

The Delay is going to make your doSomething happen in a separate thread.
 Is that acceptable?  You will need to put in locks or other
synchronization, assuming that doSomething actually has something to do
with what the main thread does.

There is no law that morphic has to be removed from your image just
because there is a web server going.  I have found it a nice
architecture to drive your entire server from morphic step methods.  You
may lose a millisecond here or there, but most of the time a few
milliseconds is nothing compared to the network delays.

But if you really do not want Morphic around, then you must have some
main loop somewhere driving everything?  So have that main loop do the
checking for what time has passed.  If you are using a framework to get
the main loop, then perhaps lobby the framework author to add a
step-like mechanism for you.

Overall, if you take either of the latter approaches, you will end up
with everything happening in a single thread.  Single-threaded
programming makes debugging easier and tends makes the code simpler to
begin with.

All IMHO of course.  Good luck with your project!

Lex



More information about the Squeak-dev mailing list