Skip to content

Commit 74ead9f

Browse files
committed
change mutex interface & update dependencies
1 parent bd28abf commit 74ead9f

21 files changed

+189
-456
lines changed

Diff for: .github/workflows/continuous-integration.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Install PHP
1414
uses: shivammathur/setup-php@v2
1515
with:
16-
php-version: 8.0
16+
php-version: 8.1
1717
coverage: none
1818
tools: composer:v2
1919

@@ -33,7 +33,7 @@ jobs:
3333
- name: Install PHP
3434
uses: shivammathur/setup-php@v2
3535
with:
36-
php-version: 8.0
36+
php-version: 8.1
3737
coverage: none
3838
tools: composer:v2
3939

@@ -53,7 +53,7 @@ jobs:
5353
- name: Install PHP
5454
uses: shivammathur/setup-php@v2
5555
with:
56-
php-version: 8.0
56+
php-version: 8.1
5757
coverage: none
5858
tools: composer:v2
5959

@@ -82,7 +82,7 @@ jobs:
8282
- name: Install PHP with extensions
8383
uses: shivammathur/setup-php@v2
8484
with:
85-
php-version: 8.0
85+
php-version: 8.1
8686
extensions: ${{ env.PHP_EXTENSIONS }}
8787
ini-values: ${{ env.PHP_INI_VALUES }}
8888
tools: composer:v2

Diff for: .php_cs.dist renamed to .php-cs-fixer.dist.php

File renamed without changes.

Diff for: composer.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@
2828
},
2929
"require": {
3030
"php": ">=8.0",
31-
"amphp/amp": "v2.5.*",
32-
"amphp/file": "v1.0.*",
31+
"amphp/amp": "v2.6.*",
32+
"amphp/file": "v2.0.*",
3333
"amphp/redis": "v1.0.*"
3434
},
3535
"require-dev": {
36-
"php-service-bus/code-style-config": "v1.3.*",
36+
"php-service-bus/code-style-config": "v5.1.*",
3737
"phpunit/phpunit": "v9.5.*",
38-
"vimeo/psalm": "v4.6.*",
39-
"phpstan/phpstan": "v0.12.*"
38+
"vimeo/psalm": "v4.12.*",
39+
"phpstan/phpstan": "v1.1.*"
4040
},
4141
"prefer-stable": true,
4242
"minimum-stability": "dev",
4343
"scripts": {
4444
"psalm": "rm -rf ~/.cache/psalm/ && ./vendor/bin/psalm --config=psalm.xml",
4545
"phpstan": "./vendor/bin/phpstan analyse src --level 7",
46-
"tests": "./vendor/bin/phpunit --configuration phpunit.xml --debug --verbose --debug",
47-
"coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --configuration phpunit.xml --coverage-html ./coverage --debug --verbose --debug",
48-
"cs-check": "./vendor/bin/php-cs-fixer fix --allow-risky=yes --dry-run",
49-
"cs-fix": "./vendor/bin/php-cs-fixer fix --allow-risky=yes",
46+
"tests": "./vendor/bin/phpunit --configuration phpunit.xml --verbose --debug",
47+
"coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --configuration phpunit.xml --coverage-html ./coverage --verbose --debug",
48+
"cs-check": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --allow-risky=yes --dry-run",
49+
"cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --allow-risky=yes",
5050
"pre-commit": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --allow-risky=yes && ./vendor/bin/psalm --config=psalm.xml && ./vendor/bin/phpstan analyse src --level 7 && ./vendor/bin/phpunit --configuration phpunit.xml --verbose"
5151
},
5252
"config": {

Diff for: phpstan.neon

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
parameters:
2-
2+
checkMissingIterableValueType: false
3+
checkGenericClassInNonGenericObjectType: false

Diff for: phpunit.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
backupStaticAttributes="false" beStrictAboutTestsThatDoNotTestAnything="false" colors="true" verbose="true"
44
convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true"
55
failOnRisky="true" failOnWarning="true" stopOnFailure="false"
6-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
6+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd">
77
<coverage>
88
<include>
99
<directory>./src</directory>
@@ -17,7 +17,7 @@
1717
<env name="REDIS_CONNECTION_DSN" value="tcp://localhost:6379"/>
1818
</php>
1919
<testsuites>
20-
<testsuite name="Mutex component">
20+
<testsuite name="Common component">
2121
<directory>./tests/</directory>
2222
</testsuite>
2323
</testsuites>

Diff for: psalm.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
totallyTyped="true"
44
useDocblockTypes="true"
55
useDocblockPropertyTypes="true"
6-
allowPhpStormGenerics="true"
76
strictBinaryOperands="true"
87
findUnusedPsalmSuppress="true"
98
ignoreInternalFunctionFalseReturn="false"
@@ -21,5 +20,6 @@
2120

2221
<issueHandlers>
2322
<PropertyNotSetInConstructor errorLevel="suppress"/>
23+
<UnnecessaryVarAnnotation errorLevel="suppress"/>
2424
</issueHandlers>
25-
</psalm>
25+
</psalm>

Diff for: src/AmpLock.php

-76
This file was deleted.

Diff for: src/Exceptions/SyncException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @license https://opensource.org/licenses/MIT
99
*/
1010

11-
declare(strict_types = 0);
11+
declare(strict_types=0);
1212

1313
namespace ServiceBus\Mutex\Exceptions;
1414

Diff for: src/InMemory/InMemoryMutex.php

-69
This file was deleted.

Diff for: src/InMemory/InMemoryMutexFactory.php

-27
This file was deleted.

Diff for: src/InMemory/InMemoryMutexService.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/**
4+
* PHP Mutex implementation.
5+
*
6+
* @author Maksim Masiukevich <[email protected]>
7+
* @license MIT
8+
* @license https://opensource.org/licenses/MIT
9+
*/
10+
11+
declare(strict_types=0);
12+
13+
namespace ServiceBus\Mutex\InMemory;
14+
15+
use Amp\Promise;
16+
use ServiceBus\Mutex\MutexService;
17+
use function Amp\call;
18+
use function Amp\delay;
19+
20+
/**
21+
* Can only be used when working in one process.
22+
*/
23+
final class InMemoryMutexService implements MutexService
24+
{
25+
private const LATENCY_TIMEOUT = 50;
26+
27+
public function withLock(string $id, callable $code): Promise
28+
{
29+
return call(
30+
static function () use ($id, $code): \Generator
31+
{
32+
try
33+
{
34+
while (InMemoryMutexStorage::instance()->has($id))
35+
{
36+
yield delay(self::LATENCY_TIMEOUT);
37+
}
38+
39+
InMemoryMutexStorage::instance()->lock($id);
40+
41+
yield $code();
42+
}
43+
finally
44+
{
45+
InMemoryMutexStorage::instance()->unlock($id);
46+
}
47+
}
48+
);
49+
}
50+
}

Diff for: src/InMemory/InMemoryMutexStorage.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @license https://opensource.org/licenses/MIT
99
*/
1010

11-
declare(strict_types = 0);
11+
declare(strict_types=0);
1212

1313
namespace ServiceBus\Mutex\InMemory;
1414

Diff for: src/Lock.php

-40
This file was deleted.

0 commit comments

Comments
 (0)