withLock function
Execute a callback while holding a lock. Returns true if the callback executed, false if lock couldn't be acquired.
Implementation
Future<bool> withLock(
String versionPath,
String lockFilePath,
Future<void> Function() callback,
) async {
final release = await tryAcquireLock(versionPath, lockFilePath);
if (release == null) return false;
try {
await callback();
return true;
} finally {
release();
}
}