Accurate clock in Erlang
        Posted  
        
            by 
                buddhabrot
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by buddhabrot
        
        
        
        Published on 2010-12-27T14:51:23Z
        Indexed on 
            2010/12/27
            14:53 UTC
        
        
        Read the original article
        Hit count: 216
        
erlang
I was thinking about how to implement a process that gives the number of discrete intervals in time that occurred since it started. Am I losing accuracy here? How do I implement this without loss of accuracy after a while and after heavy client abuse. I am kind of stumped how to do this in Erlang.
-module(clock).
-compile([export_all]).
start(Time) ->
    register(clock, spawn(fun() -> tick(Time, 0) end)).
stop() -> clock ! stop.
tick(Time, Count) ->
    receive
        nticks ->
            io:format("~p ticks have passed since start~n", [Count])
    after 0 -> true
    end,
    receive
        stop ->
            void
    after Time ->
            tick(Time, Count + 1)
    end.
© Stack Overflow or respective owner