File tree Expand file tree Collapse file tree 1 file changed +19
-6
lines changed Expand file tree Collapse file tree 1 file changed +19
-6
lines changed Original file line number Diff line number Diff line change 14
14
*/
15
15
class Loop
16
16
{
17
+
18
+ /**
19
+ * Minimum time that we want to wait, between lock checks.
20
+ *
21
+ * In micro seconds.
22
+ */
23
+ private const MINIMUM_WAIT_US = 1e4 ;
24
+
25
+ /**
26
+ * Maximum time that we want to wait, between lock checks.
27
+ *
28
+ * In micro seconds.
29
+ */
30
+ private const MAXIMUM_WAIT_US = 1e6 ;
17
31
18
32
/**
19
33
* @var int The timeout in seconds.
@@ -69,7 +83,6 @@ public function execute(callable $code)
69
83
{
70
84
$ this ->looping = true ;
71
85
72
- $ minWait = 100 ; // microseconds
73
86
$ deadline = microtime (true ) + $ this ->timeout ; // At this time, the lock will time out.
74
87
$ result = null ;
75
88
@@ -79,9 +92,6 @@ public function execute(callable $code)
79
92
break ;
80
93
}
81
94
82
- $ min = (int ) $ minWait * 1.5 ** $ i ;
83
- $ max = $ min * 2 ;
84
-
85
95
/*
86
96
* Calculate max time remaining, don't sleep any longer than that.
87
97
*/
@@ -94,9 +104,12 @@ public function execute(callable $code)
94
104
throw TimeoutException::create ($ this ->timeout );
95
105
}
96
106
97
- $ usleep = \min ($ usecRemaining , \random_int ($ min , $ max ));
107
+ $ min = min ((int ) self ::MINIMUM_WAIT_US * 1.5 ** $ i , self ::MAXIMUM_WAIT_US );
108
+ $ max = min ($ min * 2 , self ::MAXIMUM_WAIT_US );
109
+
110
+ $ usecToSleep = \min ($ usecRemaining , \random_int ($ min , $ max ));
98
111
99
- usleep ($ usleep );
112
+ usleep ($ usecToSleep );
100
113
}
101
114
102
115
if (microtime (true ) >= $ deadline ) {
You can’t perform that action at this time.
0 commit comments