acquire method

Future<void> acquire()
inherited

Acquire the semaphore. If the internal counter is greater then 0, decrease it by 1 and return immediately. If the internal counter equals 0, wait asynchronously until the semaphore is available.

Implementation

Future<void> acquire() async {
  if (_value > 0 && _waiters.isEmpty) {
    _value--;
    return;
  }

  var waiter = _FutureWaiter();
  _waiters.add(waiter);

  return waiter.future;
}