tryAcquire method

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

Tries to acquire the permit and returns true if the permit was acquired before the timeout expires, otherwise the acquisition attempt is canceled and false is returned.

Parameters:

  • timeout: The period of time during which an attempt to acquire the permit will be performed.

Implementation

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

  return _queue.enqueue(timeout);
}