[erlang-questions] writing a delay loop without now()

Paul Fisher pfisher@REDACTED
Wed Feb 18 02:32:05 CET 2009

James Hague wrote:
> I need more resolution than timer:sleep() will give me. (timer:sleep
> gives widely varying results, based on the underlying operating
> system).  Ugly though it may be, I've been using a spin loop based on
> now() and timer:now_diff().  While this appears to work, based on the
> values returned by now(), it runs much faster than wall clock time.
> I'm assuming it's because of this:
> "It is also guaranteed that subsequent calls to this BIF returns
> continuously increasing values."
> Is there another BIF I should be using?  I'm hoping I don't have to
> write my own linked-in driver for this.

sleep( Milliseconds ) ->
     receive after Milliseconds -> ok end.


More information about the erlang-questions mailing list