acquire method

Future<void> acquire()

Waits until the mutex is available, then acquires it. Completes when the mutex is acquired. Throws Object if the underlying future completes with an error.

Implementation

Future<void> acquire() async {
  if (!_isLocked) {
    _isLocked = true;
    return;
  }
  final Completer<void> c = Completer<void>();

  _waiters.add(c);
  try {
    await c.future;
  } on Object catch (e, st) {
    if (!c.isCompleted) c.completeError(e, st);
    rethrow;
  }
}