[erlang-questions] How to wake up hibernated process without sending message from external process

Ahmed Omar <>
Mon Oct 25 14:51:48 CEST 2010


You could use
erlang:send_after(Time, Dest, Msg), e.g :  erlang:send_after(1000, self(),
wakeup).
http://www.erlang.org/doc/man/erlang.html#send_after-3
On Mon, Oct 25, 2010 at 2:43 PM, Zvi <> wrote:

> 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.
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
>
>


-- 
Best Regards,
- Ahmed Omar
http://nl.linkedin.com/in/adiaa
Follow me on twitter
@spawn_think <http://twitter.com/#!/spawn_think>


More information about the erlang-questions mailing list