lock
lock copied to clipboard
Locked timeout
Spinlock with a twist (pun intended 😉)
Problem: I needed to throw an exception if the lock is already taken, but only after a given timeout.
Proposed solution
The spinlock already has its own timeout (eg: 5 seconds). With this new option: lockedTimeout
you can now specify a timeout while lock is already taken. (eg: 3 seconds).
The process will try to acquire the lock for 3 seconds then throw an exception if it doesn't succeed.
If we specify a lockedTimeout
of 0, the exception will be thrown immediately after the first lock acquire attempt.
This (with a lockedTimeout
of zero) also addresses:
https://github.com/php-lock/lock/issues/21#issuecomment-394963109
Thanks. So you want to have a different timeout for acquiring the lock and the maximum lock execution, correct?
I think we should name the two locks then $acquisitionTimeout
and $executionTimeout
.
Could you update all the files to change the naming, I'll have a better look in the coming days.
this PR seems pretty interesting, is it still alive? Long time without any update on it...