tryWait method
Releases the lock and waits for a notification.
Upon receiving the notification, the lock will be reacquired. Accordingly,
upon exiting the method, the locked code will be entered.
Returns true if the timeout has not expired; otherwise, returns false.
Implementation
@useResult
Future<bool> tryWait(Duration timeout) async {
final started = TimeUtils.elapsedMicroseconds;
if (timeout.isNegative) {
throw ArgumentError.value(
timeout, 'timeout', 'Timeout must not be negative');
}
await lock.release();
await _queue.enqueue();
return TimeUtils.elapsedMicroseconds - started < timeout.inMicroseconds;
}