/Angel/Util.hs
http://github.com/jamwt/Angel · Haskell · 19 lines · 13 code · 3 blank · 3 comment · 1 complexity · 23d26a3afdcfc2a6474c86bce0b06361 MD5 · raw file
- -- |various utility functions
- module Angel.Util where
- import Control.Concurrent
- import Control.Concurrent.STM
- import Control.Concurrent.STM.TVar (readTVar, writeTVar)
- import Control.Concurrent (threadDelay, forkIO, forkOS)
- -- |sleep for `s` seconds in an thread
- sleepSecs :: Int -> IO ()
- sleepSecs s = threadDelay $ s * 1000000
- -- |wait for the STM TVar to be non-nothing
- waitForWake :: TVar (Maybe Int) -> IO ()
- waitForWake wakeSig = atomically $ do
- state <- readTVar wakeSig
- case state of
- Just x -> writeTVar wakeSig Nothing
- Nothing -> retry