8000 Documentation for timer drift for periodic timers · reactphp/event-loop@f432daa · GitHub
[go: up one dir, main page]

Skip to content

Commit f432daa

Browse files
committed
Documentation for timer drift for periodic timers
1 parent a3d4bdd commit f432daa

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ Similarly, the execution order of timers scheduled to execute at the
293293
same time (within its possible accuracy) is not guaranteed.
294294

295295
This interface suggests that event loop implementations SHOULD use a
296-
monotic time source if available. Given that a monotonic time source is
296+
monotonic time source if available. Given that a monotonic time source is
297297
not available on PHP by default, event loop implementations MAY fall back
298298
to using wall-clock time.
299299
While this does not affect many common use cases, this is an important
@@ -365,6 +365,22 @@ to rely on this high precision.
365365
Similarly, the execution order of timers scheduled to execute at the
366366
same time (within its possible accuracy) is not guaranteed.
367367

368+
This interface suggests that event loop implementations SHOULD use a
369+
monotonic time source if available. Given that a monotonic time source is
370+
not available on PHP by default, event loop implementations MAY fall back
371+
to using wall-clock time.
372+
While this does not affect many common use cases, this is an important
373+
distinction for programs that rely on a high time precision or on systems
374+
that are subject to discontinuous time adjustments (time jumps).
375+
This means that if you schedule a timer to trigger in 30s and then adjust
376+
your system time forward by 20s, the timer SHOULD still trigger in 30s.
377+
See also [event loop implementations](#loop-implementations) for more details.
378+
379+
Additionally, periodic timers may be subject to timer drift due to
380+
re-scheduling after each invocation. As such, it's generally not
381+
recommended to rely on this for high precision intervals with millisecond
382+
accuracy or below.
383+
368384
#### cancelTimer()
369385

370386
The `cancelTimer(TimerInterface $timer): void` method can be used to

src/LoopInterface.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@ public function removeWriteStream($stream);
179179
* Similarly, the execution order of timers scheduled to execute at the
180180
* same time (within its possible accuracy) is not guaranteed.
181181
*
182+
* This interface suggests that event loop implementations SHOULD use a
183+
* monotonic time source if available. Given that a monotonic time source is
184+
* not available on PHP by default, event loop implementations MAY fall back
185+
* to using wall-clock time.
186+
* While this does not affect many common use cases, this is an important
187+
* distinction for programs that rely on a high time precision or on systems
188+
* that are subject to discontinuous time adjustments (time jumps).
189+
* This means that if you schedule a timer to trigger in 30s and then adjust
190+
* your system time forward by 20s, the timer SHOULD still trigger in 30s.
191+
* See also [event loop implementations](#loop-implementations) for more details.
192+
*
182193
* @param int|float $interval The number of seconds to wait before execution.
183194
* @param callable $callback The callback to invoke.
184195
*
@@ -247,7 +258,7 @@ public function addTimer($interval, $callback);
247258
* same time (within its possible accuracy) is not guaranteed.
248259
*
249260
* This interface suggests that event loop implementations SHOULD use a
250-
* monotic time source if available. Given that a monotonic time source is
261+
* monotonic time source if available. Given that a monotonic time source is
251262
* not available on PHP by default, event loop implementations MAY fall back
252263
* to using wall-clock time.
253264
* While this does not affect many common use cases, this is an important
@@ -257,6 +268,11 @@ public function addTimer($interval, $callback);
257268
* your system time forward by 20s, the timer SHOULD still trigger in 30s.
258269
* See also [event loop implementations](#loop-implementations) for more details.
259270
*
271+
* Additionally, periodic timers may be subject to timer drift due to
272+
* re-scheduling after each invocation. As such, it's generally not
273+
* recommended to rely on this for high precision intervals with millisecond
274+
* accuracy or below.
275+
*
260276
* @param int|float $interval The number of seconds to wait before execution.
261277
* @param callable $callback The callback to invoke.
262278
*

0 commit comments

Comments
 (0)
0