Skip to content

Commit a613eb8

Browse files
committed
Change mutex closure return declaration
1 parent b3df9ad commit a613eb8

File tree

5 files changed

+9
-14
lines changed

5 files changed

+9
-14
lines changed

src/InMemory/InMemoryMutexService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static function () use ($id, $code): \Generator
3838

3939
InMemoryMutexStorage::instance()->lock($id);
4040

41-
yield $code();
41+
yield call($code);
4242
}
4343
finally
4444
{

src/MutexService.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
interface MutexService
2121
{
2222
/**
23-
* @param callable():Promise $code
23+
* @template T as Promise|\Generator|mixed
2424
*
25-
* @return Promise<void>
25+
* @param callable(): T $code
26+
*
27+
* @return Promise<mixed>
2628
*/
2729
public function withLock(string $id, callable $code): Promise;
2830
}

src/Redis/RedisMutexService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function () use ($id, $code): \Generator
5454
}
5555

5656
yield $this->client->set($id, 'lock', $this->lockOptions);
57-
yield $code();
57+
yield call($code);
5858
}
5959
finally
6060
{

tests/InMemory/InMemoryMutexServiceTest.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ static function (): \Generator
4343

4444
yield $mutexService->withLock(
4545
$id,
46-
static function () use ($id): Promise
46+
static function () use ($id): void
4747
{
4848
self::assertTrue(InMemoryMutexStorage::instance()->has($id));
49-
50-
return new Success();
5149
}
5250
);
5351

tests/Redis/RedisMutexServiceTest.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,9 @@ function (): \Generator
6161

6262
yield $mutexService->withLock(
6363
$id,
64-
function () use ($id): Promise
64+
function () use ($id): \Generator
6565
{
66-
return call(
67-
function () use ($id): \Generator
68-
{
69-
self::assertTrue(yield $this->client->has($id));
70-
}
71-
);
66+
self::assertTrue(yield $this->client->has($id));
7267
}
7368
);
7469

0 commit comments

Comments
 (0)