 
 	getLock: (doc_id, callback = (error, lockValue) ->) ->
 		startTime = Date.now()
+		testInterval = LockManager.LOCK_TEST_INTERVAL
 		do attempt = () ->
 			if Date.now() - startTime > LockManager.MAX_LOCK_WAIT_TIME
 				e = new Error("Timeout")

				if gotLock
					callback(null, lockValue)
				else
					setTimeout attempt, LockManager.LOCK_TEST_INTERVAL

	checkLock: (doc_id, callback = (err, isFree)->)->
		key = keys.blockingKey(doc_id:doc_id)


module.exports = LockManager =
	LOCK_TEST_INTERVAL: 50 # 50ms between each test of the lock
	MAX_TEST_INTERVAL: 1000 # back off to 1s between each test of the lock
	MAX_LOCK_WAIT_TIME: 10000 # 10s maximum time to spend trying to get the lock
	LOCK_TTL: 30 # seconds. Time until lock auto expires in redis.

