acquireProcessLifetimeLock function

Future<bool> acquireProcessLifetimeLock(
  1. String versionPath,
  2. String lockFilePath
)

Acquire a lock and hold it for the lifetime of the process.

Implementation

Future<bool> acquireProcessLifetimeLock(
  String versionPath,
  String lockFilePath,
) async {
  final release = await tryAcquireLock(versionPath, lockFilePath);
  if (release == null) return false;

  // Register cleanup — in Dart we rely on ProcessSignal handlers
  void cleanup() {
    try {
      release();
    } catch (_) {}
  }

  ProcessSignal.sigint.watch().listen((_) => cleanup());
  ProcessSignal.sigterm.watch().listen((_) => cleanup());

  return true;
}