module Data.SouSiT.STM (
stmSink,
stmSink',
tchanSink,
stmSource,
stmSource',
tchanSource
) where
import Data.SouSiT.Source
import Data.SouSiT.Sink
import Control.Monad
import Control.Concurrent.STM
import Control.Monad.IO.Class
stmSink :: MonadIO m => (a -> STM (Maybe r)) -> Sink a m (Maybe r)
stmSink f = maybeSink (liftIO . atomically . f)
stmSink' :: MonadIO m => (a -> STM ()) -> Sink a m ()
stmSink' f = actionSink (liftIO . atomically . f)
tchanSink :: MonadIO m => TChan a -> Sink a m ()
tchanSink chan = stmSink' (writeTChan chan)
stmSource :: MonadIO m => STM (Maybe a) -> FeedSource m a
stmSource f = actionSource (liftIO . atomically $ f)
stmSource' :: MonadIO m => STM a -> FeedSource m a
stmSource' f = actionSource (liftIO . atomically $ liftM Just f)
tchanSource :: MonadIO m => TChan a -> FeedSource m a
tchanSource c = stmSource' (readTChan c)