Methods
-
<static> lock(name, success, maxWaitMs, timeoutCallback)
-
Create a lock using the passed in name or wait until the lock can be obtained or for the maxWaitMs if it is currently in use. If maxWaitMs time has passed and the lock is not available then timeoutCallback will be called. The lock will be held until released.
Parameters:
Name Type Argument Default Description name
string unique name of lock to acquire success
function function to call when lock acquired. This function will be passed the unique id of the lock which must be used to release the lock. maxWaitMs
number <optional>
-1 number of milliseconds to wait for lock to be aquired if not available immediately timeoutCallback
function <optional>
function to call when lock could not be acquired within the specified time Throws:
-
err - if lock cannot be acquired by maxWaitMs and no timeoutCallback is specified then an exception will be thrown instead.
- Type
- string
-
-
<static> lockFor(name, success, duration, onExpiration)
-
Create a lock using the passed in name or wait until the lock can be obtained if it is currently in use. Once obtained, the lock will be held for maximum duration milliseconds or until released. When the duration period has passed the lock will be released and an optional onExpiration function will be called if provided
Parameters:
Name Type Argument Description name
string unique name of lock to acquire success
function function to call when lock acquired duration
number number of milliseconds to hold the lock onExpiration
function <optional>
function to call when lock expires -
<static> recover()
-
provides a mechanism for restarting when script errors occur that could halt execution
-
<static> release(id)
-
Release a lock using the id returned when the lock was acquired
Parameters:
Name Type Description id
guid a unique identifier for the lock returned when the lock was acquired