Skip to content

Commit 218d13a

Browse files
committed
$initialWaitTtl = 0 (sec) by default; 60 - is too big value
1 parent f339abf commit 218d13a

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
"require-dev": {
3636
"phpunit/phpunit": "^10.0",
37-
"vimeo/psalm": "^5.9"
37+
"vimeo/psalm": "^5.9 || ^6.0"
3838
},
3939
"autoload": {
4040
"psr-4": {

src/RoadRunnerStore.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ public function __construct(
2525
private readonly RR\LockInterface $lock,
2626
private readonly TokenGeneratorInterface $tokens = new RandomTokenGenerator(),
2727
private readonly float $initialTtl = 300.0,
28-
private readonly float $initialWaitTtl = 60,
28+
private readonly float $initialWaitTtl = 0,
2929
) {
3030
\assert($this->initialTtl >= 0);
3131
\assert($this->initialWaitTtl >= 0);
3232
}
3333

34-
public function withTtl(float $ttl): self
34+
public function withTtl(float $ttl, float $waitTtl = 0): self
3535
{
36-
return new self($this->lock, $this->tokens, $ttl, $this->initialWaitTtl);
36+
return new self($this->lock, $this->tokens, $ttl, $waitTtl);
3737
}
3838

3939
public function save(Key $key): void
@@ -46,7 +46,7 @@ public function save(Key $key): void
4646
/** @var non-empty-string $resource */
4747
$resource = (string)$key;
4848

49-
$status = $this->lock->lock($resource, $lockId, $this->initialTtl);
49+
$status = $this->lock->lock($resource, $lockId, $this->initialTtl, $this->initialWaitTtl);
5050

5151
if (false === $status) {
5252
throw new LockConflictedException('RoadRunner. Failed to make lock');
@@ -65,7 +65,7 @@ public function saveRead(Key $key): void
6565

6666
/** @var non-empty-string $resource */
6767
$resource = (string)$key;
68-
$status = $this->lock->lockRead($resource, $lockId, $this->initialTtl);
68+
$status = $this->lock->lockRead($resource, $lockId, $this->initialTtl, $this->initialWaitTtl);
6969

7070
if (false === $status) {
7171
throw new LockConflictedException('RoadRunner. Failed to make read lock');

tests/RoadRunnerStoreTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function testWaitAndSaveSuccess(): void
166166
{
167167
$this->rrLock->expects($this->once())
168168
->method('lock')
169-
->with('resource-name', 'random-id', 300, 60)
169+
->with('resource-name', 'random-id', 300, 0)
170170
->willReturn('lock-id');
171171

172172
$store = new RoadRunnerStore($this->rrLock, $this->tokens);
@@ -184,7 +184,7 @@ public function testWaitAndSaveFail(): void
184184

185185
$this->rrLock->expects($this->once())
186186
->method('lock')
187-
->with('resource-name', 'random-id', 300, 60)
187+
->with('resource-name', 'random-id', 300, 0)
188188
->willReturn(false);
189189

190190
$store = new RoadRunnerStore($this->rrLock, $this->tokens);

0 commit comments

Comments
 (0)