module Control.Concurrent.Chan.ReadOnly
( ReadOnlyChan
, ofChan
, readChan
, dupChan
, getChanContents
) where

import qualified Control.Concurrent.Chan as Chan
import Control.Concurrent.Chan (Chan)

newtype ReadOnlyChan a = ReadOnlyChan (Chan a)

ofChan :: Chan a -> ReadOnlyChan a
ofChan = ReadOnlyChan

readChan :: ReadOnlyChan a -> IO a
readChan (ReadOnlyChan chan) =
  Chan.readChan chan
  
dupChan :: ReadOnlyChan a -> IO (ReadOnlyChan a)
dupChan (ReadOnlyChan chan) = do
  dup <- Chan.dupChan chan
  return (ofChan dup)

getChanContents :: ReadOnlyChan a -> IO [a]
getChanContents (ReadOnlyChan chan) =
  Chan.getChanContents chan