1515use function Amp \asyncCall ;
1616use function Amp \call ;
1717use function Amp \File \get ;
18- use function Amp \File \touch ;
18+ use function Amp \File \put ;
1919use function Amp \File \unlink ;
2020use Amp \Delayed ;
2121use Amp \Promise ;
2222use ServiceBus \Mutex \Exceptions \SyncException ;
2323
2424/**
2525 * It can be used when several processes are running within the same host.
26+ *
27+ * @internal
28+ *
29+ * @see FilesystemMutexFactory
2630 */
27- final class FileMutex implements Mutex
31+ final class FilesystemMutex implements Mutex
2832{
2933 const LATENCY_TIMEOUT = 50 ;
3034
3135 /**
36+ * Mutex identifier.
37+ *
38+ * @var string
39+ */
40+ private $ id ;
41+
42+ /**
43+ * Barrier file path.
44+ *
3245 * @var string
3346 */
3447 private $ filePath ;
@@ -41,21 +54,25 @@ final class FileMutex implements Mutex
4154 private $ release ;
4255
4356 /**
57+ * @param string $id
4458 * @param string $filePath
4559 */
46- public function __construct (string $ filePath )
60+ public function __construct (string $ id , string $ filePath )
4761 {
62+ $ this ->id = $ id ;
4863 $ this ->filePath = $ filePath ;
4964 $ this ->release = function (): \Generator
5065 {
5166 try
5267 {
5368 yield unlink ($ this ->filePath );
5469 }
70+ // @codeCoverageIgnoreStart
5571 catch (\Throwable $ throwable )
5672 {
5773 /** Not interests */
5874 }
75+ // @codeCoverageIgnoreEnd
5976 };
6077 }
6178
@@ -81,9 +98,9 @@ function(): \Generator
8198 yield new Delayed (self ::LATENCY_TIMEOUT );
8299 }
83100
84- yield touch ($ this ->filePath );
101+ yield put ($ this ->filePath , '' );
85102
86- return new AmpLock ($ this ->release );
103+ return new AmpLock ($ this ->id , $ this -> release );
87104 }
88105 catch (\Throwable $ throwable )
89106 {
0 commit comments