lock<T> method

  1. @override
Future<T> lock<T>(
  1. Future<T> callback(), {
  2. Future<void>? abortTrigger,
})
override

Runs callback in a critical section.

If abortTrigger completes before the critical section was entered, an AbortException is thrown and callback will not be invoked.

Implementation

@override
Future<T> lock<T>(
  Future<T> Function() callback, {
  Future<void>? abortTrigger,
}) {
  return _internal.lock(() async {
    final file = await _acquireFileLock();
    try {
      return await callback();
    } finally {
      await _releaseFileLock(file);
    }
  }, abortTrigger: abortTrigger);
}