[erlang-questions] perform a function on a fixed time interval

Brian Williams <>
Tue Aug 24 15:27:44 CEST 2010

On Tue, Aug 24, 2010 at 7:06 AM, Roberto Ostinelli <> wrote:
> 2010/8/24 Mazen Harake <>:
>>  Be cautious,
>> Using send messages in an interval is dangerous if compute() can take more
>> then the interval. It can build up message queues on a congested system;
>> especially if what compute() does has side effects.
>> Just a word of advise.
> you are absolutely right, and i'm aware of the issue.
> it's a game engine which needs to detect collision between particles,
> and thus it needs to periodically compute the position of all elements
> and see if these collide or not.
> what would you recommend to ensure avoiding this issue?

Another option is to spawn off another process to run the computation.
If you receive another request to compute() before this process is
finished, you can either ignore the first compute's return, send it a
stop signal of some kind or handle its partial computation somehow.
Then spawn off the new computation. This also gives you the
opportunity to log an event of some kind whenever the computation runs
too long and you can track it down.

Personally I prefer the idea of a computation process that receives a
tick message, that way it can handle its own state, and keep that
updated by other messages in between ticks.

Brian E. Williams


"Never attribute to malice that which can be adequately
explained by stupidity." - Hanlon's Razor

More information about the erlang-questions mailing list