UnfairSemaphore class
A UnfairSemaphore is a synchronization primitive that limits the number of concurrent accesses to a shared resource. It is similar to a Semaphore, but it wakes up the last future that called acquire instead of the first (i.e. waiting futures are put in a LIFO queue).
Constructors
- UnfairSemaphore(int value)
-
Create a new UnfairSemaphore object with the initial internal counter set to
value
.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- locked → bool
-
Whether this semaphore cannot be acquired immediately.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- waiters → int
-
Number of futures which are currently waiting to acquire this semaphore.
no setterinherited
Methods
-
acquire(
) → Future< void> -
Acquire the semaphore.
If the internal counter is greater then 0, decrease it by 1 and return immediately.
If the internal counter equals 0, wait asynchronously until the semaphore is available.
inherited
-
cancelAll(
) → void -
Cancel all futures waiting for this semaphore to be available by throwing a
SemaphoreAcquireFailureException to them.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
release(
) → void -
Increase the internal counter by 1 and may wake up a future waiting to acquire this semaphore.
inherited
-
run<
T> (Future< T> func()) → Future<T> -
Acquire the semaphore, asynchronously run
func
and release the semaphore afterwards.inherited -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited