how to handle a complex timer process ?

info <>
Mon Jun 14 19:10:40 CEST 2010

Hi all,
I want to manage a timer with several actions.
- creation: creation of the timer process with "Period" as parameter. The timer shall be in suspend state.
- start: the timer is started.
- restart: the timer restarts with the Period.
- stop: the timer is stopped. The timer shall be in wait state. A start starts the timer.
- kill: the timer process is killed.
- after the timeout, a message is sent to another process. The timer shall be in suspend state.

For the creation, I do:
Pid = spawn (fun,?MODULE,the_timer,[Period]),
and after I manage like this:
Pid ! {start}
Pid ! {stop}
Pid ! {restart}
Pid ! {kill}

The structure of the timer is like this:

        {start}-> ???
        {stop}-> ???
        {kill}-> ???
    after Period ->
        Pid0 -> {one_message},

How to handle the state ? how to keep the time after a stop and to start again with this time ? how to kill the process ?
How to start the timer only if a start message is received ?        

More information about the erlang-questions mailing list