unGetTBMChan :: TBMChan a -> a -> STM ()
unGetTBMChan (TBMChan closed limit chan) x = do
    b <- readTVar closed
    if b
        then return () -- Discard silently
        else do
            unGetTChan chan x
            modifyTVar' limit (subtract 1)


-- | Closes the @TBMChan@, preventing any further writes.
unGetTBMChan :: TBMChan a -> a -> STM ()
unGetTBMChan (TBMChan closed limit chan) x = do
    b <- readTVar closed
    if b
        then return () -- Discard silently
        else do
            unGetTChan chan x
            modifyTVar' limit (subtract 1)


-- | Closes the @TBMChan@, preventing any further writes.
unGetTBMChan (TBMChan closed limit chan) x = do
    b <- readTVar closed
    if b
        then return () -- Discard silently
        else do
            unGetTChan chan x
            modifyTVar' limit (subtract 1)


-- | Closes the @TBMChan@, preventing any further writes.