lock method
Implementation
Future<void> lock(String name) async {
await Future.doWhile(() async {
if (_locks.containsKey(name)) {
await Future.delayed(const Duration(milliseconds: 10));
return true;
}
String path = '/var/lock/swift_' + name;
final file = File(path);
var raf = file.openSync(mode: FileMode.write);
_locks[name] = raf;
return false;
});
await _locks[name]!.lock(FileLock.blockingExclusive);
}