Very simple quantity semaphore.
Create a new semaphore with the given argument as the initially available quantity. This allows new semaphores to start with a negative, zero, or positive quantity.
Try to take a unit of value from the semaphore. This succeeds when the current quantity is
positive, and then reduces the quantity by one. Otherwise this will
retry. This will never
result in a negative quantity. If several threads are retying then which one succeeds next is
undefined -- an unlucky thread might starve.
Signal that single unit of the semaphore is available. This increases the available quantity by one.
Non-retrying version of
wait. `tryWait s` is defined as `tryN s 1`
Try to take the given value from the semaphore. This succeeds when the quantity is greater or
equal to the given value, and then subtracts the given value from the quantity. Otherwise this
retry. This will never result in a negative quantity. If several threads are retrying
then which one succeeds next is undefined -- an unlucky thread might starve.
Signal that many units of the semaphore are available. This changes the available quantity by adding the passed size.
Non-retrying version of waitN. It either takes the quantity from the semaphore like waitN and returns `Just value taken` or finds insufficient quantity to take and returns Nothing