-- | Signal that the latch has been reached by a thread. Removes one 'token'.
onLatch :: Latch -> STM ()
onLatch (CountDownLatch v) = readTVar v >>= next
    where next n | n > 0     = writeTVar v (n-1)
                 | otherwise = return ()

-- | Wait until the onLatch has been called for the specified times.
onLatch :: Latch -> STM ()
onLatch (CountDownLatch v) = readTVar v >>= next
    where next n | n > 0     = writeTVar v (n-1)
                 | otherwise = return ()

-- | Wait until the onLatch has been called for the specified times.
onLatch (CountDownLatch v) = readTVar v >>= next
    where next n | n > 0     = writeTVar v (n-1)
                 | otherwise = return ()

-- | Wait until the onLatch has been called for the specified times.