Provides a Lock object that can be acquired only after a pre-configured delay after it is released. The Lock object is created as follows:
var Lock = ;var lock = Lock;
The following APIs are available on the lock created above:
acquire(callback)- Acquire the lock. The
keyis passed to the callback of this API.
release(key)- Release the lock. The
keygot during the
acquirecall should be passed as the argument to this call. If the
keydoes not match the key of the lock then this call will be a
The lock can be in one of the following states:
AVAILABLEA lock can be successfully acquired, only when it is in the AVAILABLE state.
ACQUIREDOnce a lock is acquired, the lock is placed in the ACQUIRED state.
DELAYINGWhen a lock is released, it is immediately put in the DELAYING state for DELAY milliseconds (configurable). After the delay it is put to AVAILABLE state.
Delaying before unlocking
By default delay after a lock is released and before it is made available is set 1s. This can be cofigured either at a global level by setting the
DELAYED_LOCK_DELAY environment variable or on a per-lock basis by passing a config parameter to the
create call while creating the lock.
var 5_sec_delayed_lock = Lock
Delayed Locks can be configured either at a global level (affects all locks) or on a per-lock basis.
Locks can be configured by setting the following environment variables before requiring the
delayed_lock module for the first time.
DELAYED_LOCK_DELAY- The amount of time that the lock should be held after it is released, before making it available again. Note that this is the minimum time and not an exact time. However, it can be expected that the delay time is reasonably close to this value.
DELAYED_LOCK_TIMEOUT- If set, the lock is made available after this period of time after it is acquired or when explicitly releases by the acquirer, whichever is earlier.
DELAYED_LOCK_MIN_WAIT_TIME_BETWEEN_RETRIES' - If anacquire` call is made when the lock is not in AVAILABLE state, locking is automatically retried after 500ms. This time can be changed by setting this variable.
A lock can be configured by passing a (optional) configuration object to the
create call. The following configuration parameters are available:
delay- same effect as DELAYED_LOCK_DELAY
timeout- same effect as DELAYED_LOCK_TIMEOUT
waitTime- same effect as DELAYED_LOCK_MIN_WAIT_TIME_BETWEEN_RETRIES
$> make test
0.0.1 - Initial Release
Pull requests are very welcome :)