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 1414 */
1515class Loop
1616{
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 ;
1731
1832 /**
1933 * @var int The timeout in seconds.
@@ -69,7 +83,6 @@ public function execute(callable $code)
6983 {
7084 $ this ->looping = true ;
7185
72- $ minWait = 100 ; // microseconds
7386 $ deadline = microtime (true ) + $ this ->timeout ; // At this time, the lock will time out.
7487 $ result = null ;
7588
@@ -79,9 +92,6 @@ public function execute(callable $code)
7992 break ;
8093 }
8194
82- $ min = (int ) $ minWait * 1.5 ** $ i ;
83- $ max = $ min * 2 ;
84-
8595 /*
8696 * Calculate max time remaining, don't sleep any longer than that.
8797 */
@@ -94,9 +104,12 @@ public function execute(callable $code)
94104 throw TimeoutException::create ($ this ->timeout );
95105 }
96106
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 ));
98111
99- usleep ($ usleep );
112+ usleep ($ usecToSleep );
100113 }
101114
102115 if (microtime (true ) >= $ deadline ) {
You can’t perform that action at this time.
0 commit comments