NamedLock constructor

NamedLock({
  1. required String name,
  2. String? lockPath,
  3. String description = '',
  4. Duration timeout = const Duration(seconds: 30),
})

lockPath is the path of the directory used to store the lock file. If no lockPath is given then Directory.systemTemp/dcli/locks is used to store locks. All code that shares the lock MUST use the same lockPath. It is recommended that you pass an absolute path to ensure that the same path is used. The name is used as the suffix of the lockfile. The suffix allows multiple locks to share a single lockPath. The description, if passed, is used in error messages to describe the lock. The timeout defines how long we will wait for a lock to become available. The default timeout is infinite (null).

NamedLock(name: 'update-catalog').withLock(() {
  if (!exists('catalog'))
    createDir('catalog');
  updateCatalog();
});

Implementation

NamedLock({
  required this.name,
  String? lockPath,
  String description = '',
  Duration timeout = const Duration(seconds: 30),
})  : _timeout = timeout,
      _description = description {
  _lockPath =
      lockPath ?? join(rootPath, Directory.systemTemp.path, 'dcli', 'locks');
}