tryAcquire method

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

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

@override
@useResult
Future<bool> tryAcquire(Duration timeout) {
  if (timeout.isNegative) {
    throw ArgumentError.value(timeout, 'timeout', 'Must not be negative');
  }

  if (!_isLocked) {
    _isLocked = true;
    return _true;
  }

  return _entranceQueue.enqueue(timeout);
}