acquire method

Future<void> acquire({
  1. bool exclusive = true,
})

Acquire a lock, blocking until granted. By default takes an exclusive lock; pass exclusive: false for a shared (reader) lock.

Implementation

Future<void> acquire({bool exclusive = true}) async {
  final canon = _canonical(lockPath);
  if (_processHeld.contains(canon)) {
    throw StateError('Database file is already open in this process: $path');
  }
  final raf = await _openLockFile();
  await raf
      .lock(exclusive ? FileLock.blockingExclusive : FileLock.blockingShared);
  _raf = raf;
  _processHeld.add(canon);
}