module Control.Concurrent.STM.Util where import Control.Monad.IO.Class import Control.Concurrent.STM chanContents :: TChan x -> IO [x] chanContents ch = do x <- atomically $ do bempty <- isEmptyTChan ch if bempty then return Nothing else fmap Just $ readTChan ch maybe (return []) (\x -> do xs <- chanContents ch return (x:xs)) x ioWriteChan :: MonadIO m => TChan a -> a -> m () ioWriteChan c v = liftIO . atomically $ writeTChan c v