-- | Start a timer.
--
-- Call given action repeatedly with the passed time since the timer has been
-- started, adjusted by a given offset.  The action is called every second;
-- whenever (passed + offset) is close to (truncate $ passed + offset).
startTimer :: POSIXTime -- ^ start time
           -> Double    -- ^ offset in seconds
           -> (Double -> IO ())
           -> IO Timer
startTimer t0 s0 action = do
  m <- newMVar True
  _ <- forkIO $ run t0 (realToFrac s0) (action . realToFrac) m
  return (Timer m)


-- | Run until False is put into the MVar.
startTimer :: POSIXTime -- ^ start time
           -> Double    -- ^ offset in seconds
           -> (Double -> IO ())
           -> IO Timer
startTimer t0 s0 action = do
  m <- newMVar True
  _ <- forkIO $ run t0 (realToFrac s0) (action . realToFrac) m
  return (Timer m)


-- | Run until False is put into the MVar.
startTimer t0 s0 action = do
  m <- newMVar True
  _ <- forkIO $ run t0 (realToFrac s0) (action . realToFrac) m
  return (Timer m)


-- | Run until False is put into the MVar.