1
0
mirror of https://github.com/danog/amp.git synced 2024-11-30 04:29:08 +01:00

Addressed drifting repeat alarms

This commit is contained in:
Daniel Lowrey 2013-08-12 11:35:18 -04:00
parent c316405996
commit d3d034f0d7
2 changed files with 16 additions and 4 deletions

12
CHANGELOG.md Normal file
View File

@ -0,0 +1,12 @@
#### v0.1.2
- Addressed execution time drift in repeating native reactor alarms
#### v0.1.1
- Addressed infinite recursion in repeating callbacks
v0.1.0
------
- Initial tagged release

View File

@ -110,18 +110,18 @@ class NativeReactor implements Reactor {
foreach ($this->alarmOrder as $watcherId => $executionCutoff) {
if ($executionCutoff <= $now) {
$this->doAlarmCallback($watcherId, $now);
$this->doAlarmCallback($watcherId);
} else {
break;
}
}
}
private function doAlarmCallback($watcherId, $now) {
private function doAlarmCallback($watcherId) {
list($callback, $nextExecution, $interval, $isRepeating) = $this->alarms[$watcherId];
if ($isRepeating) {
$nextExecution = $now + $interval;
$nextExecution += $interval;
$this->alarms[$watcherId] = [$callback, $nextExecution, $interval, $isRepeating];
$this->alarmOrder[$watcherId] = $nextExecution;
} else {
@ -130,7 +130,7 @@ class NativeReactor implements Reactor {
$this->alarmOrder[$watcherId]
);
}
$callback($watcherId);
}