newTBMChanIO :: Int -> IO (TBMChan a)
newTBMChanIO n = do
    closed <- newTVarIO False
    limit  <- newTVarIO n
    chan   <- newTChanIO
    return (TBMChan closed limit chan)


-- | Read the next value from the @TBMChan@, retrying if the channel
-- is empty (and not closed). We return @Nothing@ immediately if
-- the channel is closed and empty.
newTBMChanIO :: Int -> IO (TBMChan a)
newTBMChanIO n = do
    closed <- newTVarIO False
    limit  <- newTVarIO n
    chan   <- newTChanIO
    return (TBMChan closed limit chan)


-- | Read the next value from the @TBMChan@, retrying if the channel
-- is empty (and not closed). We return @Nothing@ immediately if
-- the channel is closed and empty.
newTBMChanIO n = do
    closed <- newTVarIO False
    limit  <- newTVarIO n
    chan   <- newTChanIO
    return (TBMChan closed limit chan)


-- | Read the next value from the @TBMChan@, retrying if the channel
-- is empty (and not closed). We return @Nothing@ immediately if
-- the channel is closed and empty.