module Haskore.Basic.Timer.Posix (timer) where

import qualified Haskore.Basic.Timer as Timer
import System.Time(getClockTime)
import System.Posix.Unistd(usleep)

import qualified Numeric.NonNegative.Wrapper as NonNeg


timer :: Timer.T
timer = Timer.Cons getClockTime wait resolution


{-
sleep can be aborted with CTRL-C, but measures in seconds.
usleep measures in micro-seconds, but is unbreakable.
Non is appropriate.
-}
wait :: NonNeg.Int -> IO ()
wait delay =
   -- putStrLn ("wait " ++ show delay) >>
   -- usleep (delay*unit)
   usleep (NonNeg.toNumber delay)
   -- sleep delay >> return ()

resolution :: Num a => a
resolution = 10^(6::Int)

{-
unit :: Int
unit = div (10^(6::Int)) resolution
-}
