-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Locked timeout #35
base: master
Are you sure you want to change the base?
Locked timeout #35
Conversation
# Conflicts: # classes/mutex/SpinlockMutex.php
50b6d7f
to
81e0882
Compare
@@ -0,0 +1,10 @@ | |||
<?php | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
declare(strict_types=1); | |
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 |
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... |
* | ||
* @throws \LengthException The timeout must be greater than 0. | ||
*/ | ||
public function __construct(array $redisAPIs, string $name, int $timeout = 3) | ||
public function __construct(array $redisAPIs, string $name, int $timeout = 3, int $lockedTimeout = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?int
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:#21 (comment)