[erlang-questions] erlang:restart_timer

Rich Neswold <>
Fri Nov 7 16:30:14 CET 2014

On Wed, Nov 5, 2014 at 7:50 AM, Tony Rogvall <> wrote:

> I propose a new BIF:
>         erlang:restart_timer(Ref, Time) -> false | RemainingTime
> This will restart a time if it is active and return the time that remained
> when it was restarted.
> If restart_timer return false either the timer has already time out or the
> reference is not a timer.

I like the proposal. However, is it too "imperative" of an interface? If a
process saves a timer reference and the timer never seems to fire, you have
to determine whether it was cancelled or reset. One of the strengths of
immutability is that you can always tell where a variable received its
value. By reusing the same timer ref, a long lived value may go through
many state changes which may make it harder to find bugs related to the
timer. I guess erlang:cancel_timer/1 already changes the state of a timer,
so this proposal isn't setting the precedent, just expanding it.

To keep it more functional, it should be more like:

erlang:restart_timer(ORef, Time) -> { NRef, false | RemainingTime }

The old timer gets cancelled, any messages from the old timer are removed
from the queue, and then new timer is created. A new ref is always returned
and the second value indicates the end state of the previous timer:
'false', if it expired, or the time remaining.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20141107/b4207fe4/attachment.html>

More information about the erlang-questions mailing list