lock method

Future<void> lock()

Implementation

Future<void> lock() async {
  while (_lock != null) {
    await _lock!.future;
  }

  _lock ??= Completer<void>();
  if (_owners > 0) {
    // if additional threads arrive here
    // send them back to the lock() method
    lock();
  } else {
    _owners++;
  }
}