withSessionLock<T> function

Future<T> withSessionLock<T>(
  1. String destinationPath,
  2. Future<T> action(), {
  3. String? baseDir,
  4. bool isPidAlive(
    1. int pid
    )?,
  5. int? currentPid,
})

Convenience helper executing action within a session lock.

Binds: FR-056, FR-056a.

Implementation

Future<T> withSessionLock<T>(
  String destinationPath,
  Future<T> Function() action, {
  String? baseDir,
  bool Function(int pid)? isPidAlive,
  int? currentPid,
}) async {
  final lock = await SessionLock.acquire(
    destinationPath,
    baseDir: baseDir,
    isPidAlive: isPidAlive,
    currentPid: currentPid,
  );
  try {
    return await action();
  } finally {
    await lock.release();
  }
}