PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/Angel/Util.hs

http://github.com/jamwt/Angel
Haskell | 19 lines | 13 code | 3 blank | 3 comment | 0 complexity | 23d26a3afdcfc2a6474c86bce0b06361 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. -- |various utility functions
  2. module Angel.Util where
  3. import Control.Concurrent
  4. import Control.Concurrent.STM
  5. import Control.Concurrent.STM.TVar (readTVar, writeTVar)
  6. import Control.Concurrent (threadDelay, forkIO, forkOS)
  7. -- |sleep for `s` seconds in an thread
  8. sleepSecs :: Int -> IO ()
  9. sleepSecs s = threadDelay $ s * 1000000
  10. -- |wait for the STM TVar to be non-nothing
  11. waitForWake :: TVar (Maybe Int) -> IO ()
  12. waitForWake wakeSig = atomically $ do
  13. state <- readTVar wakeSig
  14. case state of
  15. Just x -> writeTVar wakeSig Nothing
  16. Nothing -> retry