[erlang-questions] What I dislike about Erlang

Per Melin per.melin@REDACTED
Sun Sep 2 17:41:54 CEST 2012

On Sep 2, 2012, at 17:12 , Evan Miller wrote:

>>> This probably proves your point, but just to be clear old messages
>>> will only "hang around forever" if 1. there are no new messages on a
>>> channel and 2. the channel continues to receive requests. If there is
>>> no activity on a channel for max_age, the gen_server timeout is
>>> invoked here:
>>> https://github.com/evanmiller/tinymq/blob/master/src/tinymq_channel_controller.erl#L76
>> There must be a bug there. You only specify a timeout in the return of init, but that does not persist beyond the first message received. I can't see how that timeout would ever be invoked.
> Perhaps I am confused, but I thought the gen_server timeout will also
> occur between messages.

The timeout only persists until it fires or a message comes in. The timer is not restarted by a message, it is discarded. So you'll need to supply the timeout duration again in each and every reply/noreply tuple from handle_call, handle_cast and handle_info.

I find this inconvenient and very error prone though, and normally use erlang:send_after(Time, self(), timeout) instead. You'll of course need to keep track of the reference though and reset the timer yourself.

More information about the erlang-questions mailing list