How to wake up hibernated process without sending message from external process

Zvi zvi.avraham@REDACTED
Mon Oct 25 14:43:37 CEST 2010


Hi,

I have many hibernated erlang processes, which need to be periodically
waken up.
One way to do this, is to send wakeup messages from external process.
Is there a scalable way for the hibernated process to send messages to
itself via some kind of periodic timer?

Also note, that "after" doesn't work for hibernated processes. In
order to "after" clause to work, the process need to be
"unhibernated".

Thanks,
Zvi

================================
-module(mymodule).
-export([start/0, loop/1]).

start() ->
    proc_lib:hibernate(?MODULE, loop, [0]);

loop(State) ->
    receive
        {do_something, Msg} ->
              State2 = do_something(State, Msg),
              proc_lib:hibernate(?MODULE, loop, [State2]);
        wakeup ->
              loop(State)
    after Timeout ->
              do_cleanup()
    end.


More information about the erlang-questions mailing list