Skip to content

ReleaseLockAsync

Asynchronously releases a previously acquired lock.

1
$Cache.ReleaseLockAsync(key: string, token: string):Promise<boolean>

Parameters

string key
    The shared lock key. Required.

string token
    The token returned when the lock was acquired. Required.

Returns

A promise containing true if the lock was released successfully; otherwise, false.

Remarks

The key and token must match the values used by $Cache.LockAsync or $Cache.TryLockAsync. A lock can be released only once.

Releasing a lock in a finally block so it is also released when the protected operation fails

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
var tokenValue = await $Cache.LockAsync('mylock');
if (tokenValue != null) {
  try {
    // Locked code block
  }
  finally {
    var released = await $Cache.ReleaseLockAsync('mylock', tokenValue);
    if (!released) {
      // The lock had already expired or was released
    }
  }
}

See Also