File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -109,9 +109,22 @@ public function testSimultaneousLock(): void
109
109
$ future1 = async (fn () => $ handle1 ->lock (LockType::Exclusive));
110
110
$ future2 = async (fn () => $ handle2 ->lock (LockType::Exclusive));
111
111
112
- EventLoop::delay (0.1 , fn () => $ handle1 ->unlock ());
112
+ EventLoop::delay (0.1 , function () use ($ handle1 , $ handle2 ): void {
113
+ // Either file could obtain the lock first, so check both and release the one which obtained the lock.
114
+
115
+ if ($ handle1 ->getLockType ()) {
116
+ $ handle1 ->unlock ();
117
+ }
118
+
119
+ if ($ handle2 ->getLockType ()) {
120
+ $ handle2 ->unlock ();
121
+ }
122
+ });
113
123
114
124
$ future1 ->await ();
115
125
$ future2 ->await ();
126
+
127
+ $ handle1 ->close ();
128
+ $ handle2 ->close ();
116
129
}
117
130
}
You can’t perform that action at this time.
0 commit comments