module Control.Concurrent.Bag.TaskBuffer
 ( TaskBuffer (..)
 , BufferType (..)
 , newChanBuffer
 , newStackBuffer )
where

import Control.Concurrent.Chan
import Control.Concurrent.Stack
import Control.Concurrent.Bag.BufferType

data TaskBuffer a = TaskBuffer {
    writeBuffer :: a -> IO ()
  , readBuffer  :: IO a }

newChanBuffer :: IO (TaskBuffer r)
newChanBuffer = do
  c <- newChan
  return $ TaskBuffer (writeChan c) (readChan c)

newStackBuffer :: IO (TaskBuffer r)
newStackBuffer = do
  s <- newStack
  return $ TaskBuffer (writeStack s) (readStack s)