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 namestring unique name of lock to acquire successfunction 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. maxWaitMsnumber <optional>
-1 number of milliseconds to wait for lock to be aquired if not available immediately timeoutCallbackfunction <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 namestring unique name of lock to acquire successfunction function to call when lock acquired durationnumber number of milliseconds to hold the lock onExpirationfunction <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 idguid a unique identifier for the lock returned when the lock was acquired