[erlang-questions] Erlang Scheduler for Recurring Events

Daniel Luna daniel@REDACTED
Wed Aug 24 16:23:16 CEST 2011

On 24 August 2011 09:59, Garrett Smith <g@REDACTED> wrote:
> On Wed, Aug 24, 2011 at 6:51 AM, Hank Knight <hknight555@REDACTED> wrote:
>> Hello,
>> I need to scheduler a number of recurring events using Erlang.  Some
>> events need to be triggered every second, some every three seconds and
>> some every minute.  Any simple advise on how to do this or what tools
>> to do?
[cut away a good solution to the problem]
> Of course if you don't care about regular intervals, you can track
> your work time and subtract it from interval.

If you don't care about exact regular intervals the easiest thing
would be to use the timeout feature of gen_server.

Initialize your gen_server with {ok, State, 3000} for a three second
wait to the next event.  Add a handle_info(timeout, ...), and make
sure that you set the timeout at every return point (i.e. {noreply,
State, Timeout} for handle_info).

This of course only works if the gen_server doesn't receive messages
from elsewhere since then the timeout will never occur (it is a
timeout after all).

(If this method counts as good erlang coding style I leave to others to decide.)



More information about the erlang-questions mailing list