[erlang-questions] gen_server equivalent of "after"?

Jani Launonen <>
Sat Jan 19 10:25:29 CET 2008


Hello!


Jim McCoy kirjoitti 19.1.2008 kello 7.43:

>
> In a standard receive loop it is fairly obvious how to set up a
> timeout within the loop.  When using gen_server this becomes opaque to
> the point that I am wondering if it is even possible.  I have a
> gen_server module set up to handle a task, but I want it to do some
> action if no messages are received within a certain amount of time.
> Do I really have to spawn another process just to trigger these events
> or am I missing something?

You should return {reply, Reply, NewState, Timeout} from handle_call  
(similarly from handle_cast and handle_info if that's what you want)  
if you expect the next call to happen in Timeout milliseconds. If it  
does not, handle_info(timeout, State) will be called.

Cheers,
Jani


>
> jim
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list