[erlang-questions] Restricting number of executions per second

mats cronqvist masse@REDACTED
Wed Dec 3 15:20:32 CET 2008

"Ahmed Ali" <ahmed.nawras@REDACTED> writes:

> Hi All,
> I want to run a function in not more than a specific numbers of times
> per second (e.g. 3 times per second). The function is part of a
> gen_server process (i.e. called using gen_server:call/2). What's the
> best way to do this?

  this ought to be pretty effective.
  it's just pseudo-code of course.

loop(Sec,Count) ->
  case Count < 3 of
    true -> func();
    false-> ok
  case now() of
    {_,Sec,_} -> loop(Sec,Count+1);
    {_,NSec,_}-> loop(NSec,0)

More information about the erlang-questions mailing list