module Control.Concurrent.STM.TChan.Class
where
import qualified Control.Concurrent.STM.TChan as C
import Control.Concurrent.STM
class SplitTChan i o | i -> o, o -> i where
writeTChan :: i a -> a -> STM ()
readTChan :: o a -> STM a
peekTChan :: o a -> STM a
tryPeekTChan :: o a -> STM (Maybe a)
tryReadTChan :: o a -> STM (Maybe a)
isEmptyTChan :: o a -> STM Bool
class (SplitTChan i o)=> NewSplitTChan i o where
newSplitTChan :: STM (i a, o a)
instance SplitTChan TMVar TMVar where
readTChan = takeTMVar
writeTChan = putTMVar
peekTChan = readTMVar
tryReadTChan = tryTakeTMVar
tryPeekTChan = tryReadTMVar
isEmptyTChan = isEmptyTMVar
instance SplitTChan C.TChan C.TChan where
writeTChan = C.writeTChan
readTChan = C.readTChan
peekTChan = C.peekTChan
tryReadTChan = C.tryReadTChan
tryPeekTChan = C.tryPeekTChan
isEmptyTChan = C.isEmptyTChan
instance NewSplitTChan TMVar TMVar where
newSplitTChan = do v <- newEmptyTMVar
return (v,v)
instance NewSplitTChan TChan TChan where
newSplitTChan = do v <- C.newTChan
return (v,v)