renew method

  1. @override
Future<bool> renew(
  1. String key,
  2. String owner,
  3. Duration ttl
)
override

Extends the lock TTL when the owner still holds it.

Implementation

@override
/// Extends the lock TTL when the [owner] still holds it.
Future<bool> renew(String key, String owner, Duration ttl) async {
  final lock = _locks[key];
  if (lock == null) {
    return false;
  }
  if (lock.owner != owner) {
    return false;
  }
  final now = stemNow();
  if (lock.isExpired(now)) {
    _locks.remove(key);
    return false;
  }
  lock.expiresAt = now.add(ttl);
  return true;
}