module Sound.Osc.Time.Thread where
import Control.Concurrent
import Control.Monad
import Sound.Osc.Time
pauseThreadLimit :: Fractional n => n
pauseThreadLimit :: forall n. Fractional n => n
pauseThreadLimit = forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Bounded a => a
maxBound::Int) forall a. Fractional a => a -> a -> a
/ n
1e6
pauseThreadFor :: RealFrac n => n -> IO ()
pauseThreadFor :: forall n. RealFrac n => n -> IO ()
pauseThreadFor n
n = forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (n
n forall a. Ord a => a -> a -> Bool
> n
0) (Int -> IO ()
threadDelay (forall a b. (RealFrac a, Integral b) => a -> b
floor (n
n forall a. Num a => a -> a -> a
* n
1e6)))
pauseThreadUntilTime :: RealFrac n => n -> IO ()
pauseThreadUntilTime :: forall n. RealFrac n => n -> IO ()
pauseThreadUntilTime n
t = forall n. RealFrac n => n -> IO ()
pauseThreadFor forall b c a. (b -> c) -> (a -> b) -> a -> c
. (n
t forall a. Num a => a -> a -> a
-) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Real a, Fractional b) => a -> b
realToFrac forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< IO NtpReal
currentTime
sleepThreadFor :: RealFrac n => n -> IO ()
sleepThreadFor :: forall n. RealFrac n => n -> IO ()
sleepThreadFor n
n =
if n
n forall a. Ord a => a -> a -> Bool
>= forall n. Fractional n => n
pauseThreadLimit
then let n' :: n
n' = forall n. Fractional n => n
pauseThreadLimit forall a. Num a => a -> a -> a
- n
1
in forall n. RealFrac n => n -> IO ()
pauseThreadFor n
n' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall n. RealFrac n => n -> IO ()
sleepThreadFor (n
n forall a. Num a => a -> a -> a
- n
n')
else forall n. RealFrac n => n -> IO ()
pauseThreadFor n
n
sleepThreadUntilTime :: RealFrac n => n -> IO ()
sleepThreadUntilTime :: forall n. RealFrac n => n -> IO ()
sleepThreadUntilTime n
t = forall n. RealFrac n => n -> IO ()
sleepThreadFor forall b c a. (b -> c) -> (a -> b) -> a -> c
. (n
t forall a. Num a => a -> a -> a
-) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Real a, Fractional b) => a -> b
realToFrac forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< IO NtpReal
currentTime