Skip to content

Commit c88e224

Browse files
committed
Update Psalm and fix issues
1 parent a404df9 commit c88e224

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232
"revolt/event-loop": "^1 || ^0.2"
3333
},
3434
"require-dev": {
35+
"ext-shmop": "*",
36+
"ext-sysvmsg": "*",
3537
"phpunit/phpunit": "^9",
3638
"amphp/phpunit-util": "^3",
3739
"amphp/php-cs-fixer-config": "^2",
38-
"psalm/phar": "^5.4"
40+
"psalm/phar": "5.23"
3941
},
4042
"autoload": {
4143
"psr-4": {

src/Lock.php

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use SplObjectStorage;
66
use function Amp\async;
77
use function Amp\Future\awaitAll;
8-
use function register_shutdown_function;
98

109
/**
1110
* A handle on an acquired lock from a synchronization object.
@@ -15,7 +14,7 @@
1514
*/
1615
final class Lock
1716
{
18-
private static \Fiber $testFiber;
17+
private static ?\Fiber $testFiber = null;
1918

2019
private static ?\SplObjectStorage $pendingOperations = null;
2120

@@ -34,17 +33,15 @@ public function __construct(\Closure $release)
3433

3534
private static function setupPendingOperations(): SplObjectStorage
3635
{
37-
if (self::$pendingOperations === null) {
38-
self::$pendingOperations = new SplObjectStorage();
39-
40-
register_shutdown_function(static function () {
41-
while (self::$pendingOperations->count() > 0) {
42-
awaitAll(self::$pendingOperations);
43-
}
44-
});
45-
}
36+
$pending = new SplObjectStorage();
37+
38+
\register_shutdown_function(static function () use ($pending): void {
39+
while ($pending->count() > 0) {
40+
awaitAll($pending);
41+
}
42+
});
4643

47-
return self::$pendingOperations;
44+
return $pending;
4845
}
4946

5047
/**
@@ -73,9 +70,9 @@ public function release(): void
7370
if ($this->isForceClosed()) {
7471
$future = async($release);
7572

76-
self::$pendingOperations = self::setupPendingOperations();
77-
self::$pendingOperations->attach($future);
78-
$future->finally(fn () => self::$pendingOperations->detach($future));
73+
$pending = self::$pendingOperations ??= self::setupPendingOperations();
74+
$pending->attach($future);
75+
$future->finally(fn () => $pending->detach($future));
7976
} else {
8077
$release();
8178
}
@@ -94,17 +91,17 @@ public function __destruct()
9491

9592
private function isForceClosed(): bool
9693
{
97-
self::$testFiber ??= new \Fiber(function () {
94+
$fiber = self::$testFiber ??= new \Fiber(function () {
9895
while (true) {
9996
\Fiber::suspend();
10097
}
10198
});
10299

103100
try {
104-
if (self::$testFiber->isStarted()) {
105-
self::$testFiber->resume();
101+
if ($fiber->isStarted()) {
102+
$fiber->resume();
106103
} else {
107-
self::$testFiber->start();
104+
$fiber->start();
108105
}
109106

110107
return false;

0 commit comments

Comments
 (0)