NamedLock constructor

NamedLock({
  1. required String name,
  2. String description = '',
  3. String suffix = 'dcli.lck',
  4. Duration timeout = const Duration(days: 1),
})

All code that shares the lock MUST use the same name and suffix.

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 1 day.

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

Implementation

NamedLock({
  required this.name,
  String description = '',
  String suffix = 'dcli.lck',
  Duration timeout = const Duration(days: 1),
})  : _timeout = timeout,
      _description = description,
      _nameWithSuffix = [name, suffix].join('.');