Constructs a semaphore with maxWaiters
as the limit on the
number of waiters for permits.
Constructs a semaphore with maxWaiters
as the limit on the
number of waiters for permits.
must be positive
must be non-negative
Constructs a semaphore with no limit on the max number of waiters for permits.
Constructs a semaphore with no limit on the max number of waiters for permits.
must be positive
Acquire a Permit, asynchronously.
Acquire a Permit, asynchronously. Be sure to permit.release()
in a
- finally
block of your onSuccess
callback
- ensure
block of your future chain
Interrupting this future is only advisory, and will not release the permit if the future has already been satisfied.
a Future[Permit]
when the Future
is satisfied, computation can proceed,
or a Future.Exception[RejectedExecutionException] if the configured maximum
number of waiters would be exceeded.
This method always return the same instance of Permit.
Execute the function asynchronously when a permit becomes available.
Execute the function asynchronously when a permit becomes available.
If the function throws a non-fatal exception, the exception is returned as part of the Future. For all exceptions, the permit would be released before returning.
a Future[T] equivalent to the return value of the input function. If the configured maximum value of waitq is reached, Future.Exception[RejectedExecutionException] is returned.
Execute the function when a permit becomes available.
Execute the function when a permit becomes available.
If the function throws an exception, the exception is returned as part of the Future. For all exceptions, the permit would be released before returning.
a Future[T] equivalent to the return value of the input function. If the configured maximum value of waitq is reached, Future.Exception[RejectedExecutionException] is returned.
Fail the semaphore and stop it from distributing further permits.
Fail the semaphore and stop it from distributing further permits. Subsequent
attempts to acquire a permit fail with exc
. This semaphore's queued waiters
are also failed with exc
.
An AsyncSemaphore is a traditional semaphore but with asynchronous execution.
Grabbing a permit returns a
Future[Permit]
.Basic usage:
Calls to acquire() and acquireAndRun are serialized, and tickets are given out fairly (in order of arrival).
AsyncMutex for a mutex version.