tryAcquireLock method
Makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result.
correlationId
(optional) transaction id to trace execution through call chain.key
a unique lock key to acquire.ttl
a lock timeout (time to live) in milliseconds. Return Future that receives a lock result Throws error.
Implementation
@override
Future<bool> tryAcquireLock(
String? correlationId, String key, int ttl) async {
var expireTime = _locks[key];
var now = DateTime.now().toUtc().millisecondsSinceEpoch;
if (expireTime == null || expireTime < now) {
_locks[key] = now + ttl;
return true;
} else {
return false;
}
}