tryAcquire method
Tries to acquire the lock and returns true if the lock 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 thelockwill be performed.
Implementation
@override
@useResult
Future<bool> tryAcquire(Duration timeout) async {
if (_owner == null) {
_owner = Zone.current;
_count++;
return true;
}
if (_owner == Zone.current) {
_count++;
return true;
}
final isSuccess = await _entranceQueue.enqueue(timeout);
if (isSuccess) {
_owner = Zone.current;
_count++;
}
return isSuccess;
}