tryAcquire method

  1. @useResult
Future<bool> tryAcquire(
  1. Duration timeout
)

Tries to acquire a permit from this semaphore and waits until the specified timeout expires.
If the semaphore is locked and timeout is zero (or not specified), false is returned.
If the timeout expires before the semaphore is unlocked, then returns false.
If permit was acquired, returns true.

Implementation

@useResult
Future<bool> tryAcquire(Duration timeout) {
  if (_count > 0) {
    _count--;
    return _true;
  }

  return _queue.enqueue(timeout);
}