The "idle-time" gen_server Pattern

Eric Newhuis <>
Wed Mar 31 03:40:17 CEST 2010


I've been experimenting with using the handle_info(timeout, State) callback.

Push lots of crud into State by way of handle_call, handle_cast, and always return {(no)reply, State, Timeout} where Timeout = 0.  Then do CPU-bound processing in handle_info(timeout...

This causes handle_info(timeout...) to be called only when the message queue is empty.

Assumption:  handle_call/cast simply append work to do and a single algorithm is more efficient if it knows there are many queued items.

Has anyone tried this?  Any hints?  Gotchas?  I am theoretically aware (?) of the possibility of starvation.  But what else?



More information about the erlang-questions mailing list