[erlang-questions] About erlang:statistics/1 and timeout values

Per Melin <>
Fri Apr 24 01:20:14 CEST 2009

Oscar Hellström:
> back to (part of) the original question, how would we go about
> decrementing a timeout value between blocking calls. I could use now
> diffs, or erlang:start_timer/3... are there better ways?

Can it really be simpler than now_diff/2?

loop(Timeout) when Timeout > 0 ->
    Before = now(),
        X ->
            % Do whatever
            loop(Timeout - timer:now_diff(now(), Before) div 1000)
    after Timeout ->
loop(_) ->

(If I needed millisecond precision I would do it a little different
just to be sure.)

More information about the erlang-questions mailing list