Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have two easy alternatives, use <code>timer:send_interval/2</code> or <code>erlang:send_after/3</code>. <code>send_interval</code> is easier to setup, while <code>send_after</code> (when used in the Erlang module) is more reliable since it is a built-in function, see the <a href="http://www.erlang.org/doc/efficiency_guide/commoncaveats.html#id60206" rel="noreferrer">Efficiency Guide</a>.</p> <p>Using <code>send_after</code> also ensures that the <code>gen_server</code> process is not overloaded. If you were using the <code>send_interval</code> function you would get a message regardless if the process can keep up or not. With <code>send_after</code> being called just before the return in <code>handle_info</code> you only schedule a new message once you handled the previous one. If you want more accurate time tracking you can still schedule a <code>send_after</code> with the time set dynamically to something lower than <code>?INTERVAL</code> (or even 0) to catch up.</p> <p>I would recommend something along the following lines in your <code>gen_server</code>:</p> <pre><code>-define(INTERVAL, 60000). % One minute init(Args) -&gt; ... % Start first timer erlang:send_after(?INTERVAL, self(), trigger), ... handle_info(trigger, State) -&gt; ... % Do the action ... % Start new timer erlang:send_after(?INTERVAL, self(), trigger), ... </code></pre> <p>Instead of <code>trigger</code> you could send something with a state if it is needed, like <code>{trigger, Count}</code> or something.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload