synchronized<T> method
Execute body exclusively under the lock associated with key.
Implementation
@override
Future<T> synchronized<T>(String key, Future<T> Function() body) {
return _inProcess.synchronized(key, () async {
final sanitized = _sanitizeKey(key);
final lockFile = File('${lockDir.path}/$sanitized.lock');
if (!lockFile.existsSync()) {
try {
lockFile.createSync(recursive: true);
} catch (_) {}
}
final raf = await lockFile.open(mode: FileMode.write);
try {
await raf.lock(FileLock.blockingExclusive);
return await body();
} finally {
try {
await raf.unlock();
} catch (_) {}
try {
await raf.close();
} catch (_) {}
}
});
}