15
15
use function Amp \asyncCall ;
16
16
use function Amp \call ;
17
17
use function Amp \File \get ;
18
- use function Amp \File \touch ;
18
+ use function Amp \File \put ;
19
19
use function Amp \File \unlink ;
20
20
use Amp \Delayed ;
21
21
use Amp \Promise ;
22
22
use ServiceBus \Mutex \Exceptions \SyncException ;
23
23
24
24
/**
25
25
* It can be used when several processes are running within the same host.
26
+ *
27
+ * @internal
28
+ *
29
+ * @see FilesystemMutexFactory
26
30
*/
27
- final class FileMutex implements Mutex
31
+ final class FilesystemMutex implements Mutex
28
32
{
29
33
const LATENCY_TIMEOUT = 50 ;
30
34
31
35
/**
36
+ * Mutex identifier.
37
+ *
38
+ * @var string
39
+ */
40
+ private $ id ;
41
+
42
+ /**
43
+ * Barrier file path.
44
+ *
32
45
* @var string
33
46
*/
34
47
private $ filePath ;
@@ -41,21 +54,25 @@ final class FileMutex implements Mutex
41
54
private $ release ;
42
55
43
56
/**
57
+ * @param string $id
44
58
* @param string $filePath
45
59
*/
46
- public function __construct (string $ filePath )
60
+ public function __construct (string $ id , string $ filePath )
47
61
{
62
+ $ this ->id = $ id ;
48
63
$ this ->filePath = $ filePath ;
49
64
$ this ->release = function (): \Generator
50
65
{
51
66
try
52
67
{
53
68
yield unlink ($ this ->filePath );
54
69
}
70
+ // @codeCoverageIgnoreStart
55
71
catch (\Throwable $ throwable )
56
72
{
57
73
/** Not interests */
58
74
}
75
+ // @codeCoverageIgnoreEnd
59
76
};
60
77
}
61
78
@@ -81,9 +98,9 @@ function(): \Generator
81
98
yield new Delayed (self ::LATENCY_TIMEOUT );
82
99
}
83
100
84
- yield touch ($ this ->filePath );
101
+ yield put ($ this ->filePath , '' );
85
102
86
- return new AmpLock ($ this ->release );
103
+ return new AmpLock ($ this ->id , $ this -> release );
87
104
}
88
105
catch (\Throwable $ throwable )
89
106
{
0 commit comments