Delay and threads question

Ned Konz ned at bike-nomad.com
Thu Dec 5 01:25:32 UTC 2002


On Wednesday 04 December 2002 05:09 pm, Derek Brans wrote:
> I want an object to do something every 10 minutes.
>
> I have the following code:
>
> startTimer
>
> 	| delay |
>
> 	delay _ Delay forMilliseconds: 10 * 60 * 1000.
> 	[delay wait. true] whileTrue: [self save]
>
> My question: is it save safe to call self startTimer from
> initialize? 

Not unless you want whatever called initialize to stop doing whatever 
it was doing.

> If so, why doesn't the process that called "new" get
> trapped? If not, how should startTimer be called?

You should start another process:

startTimer
       [  | delay |
        delay _ Delay forSeconds: 10 * 60.
        [ delay wait. self save ] repeat ] forkAt: Processor 
userBackgroundPriority.

-- 
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE




More information about the Squeak-dev mailing list