Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

bstanescu
Copy link

@bstanescu bstanescu commented Oct 7, 2019

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)

@@ -0,0 +1,10 @@
<?php

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
declare(strict_types=1);

@willemstuursma
Copy link
Contributor

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.

@willemstuursma
Copy link
Contributor

Could you update all the files to change the naming, I'll have a better look in the coming days.

@pablomoreno61
Copy link

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?int

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants