mirror of
https://github.com/PerMalmberg/libcron.git
synced 2025-04-22 00:13:01 -05:00
Fix task may appear to be triggered more than 1 second late (#27)
* Fix task may appear to be triggered more than 1 second late * Add comment Co-authored-by: Per Malmberg <PerMalmberg@users.noreply.github.com>
This commit is contained in:
parent
5f8ecc9690
commit
0dd9df49d7
@ -81,6 +81,16 @@ namespace libcron
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Discard fraction seconds in the calculated schedule time
|
||||||
|
// that may leftover from the argument `from`, which in turn comes from `now()`.
|
||||||
|
// Fraction seconds will potentially make the task be triggered more than 1 second late
|
||||||
|
// if the `tick()` within the same second is earlier than schedule time,
|
||||||
|
// in that the task will not trigger until the next `tick()` next second.
|
||||||
|
// By discarding fraction seconds in the scheduled time,
|
||||||
|
// the `tick()` within the same second will never be earlier than schedule time,
|
||||||
|
// and the task will trigger in that `tick()`.
|
||||||
|
curr -= curr.time_since_epoch() % seconds{1};
|
||||||
|
|
||||||
return std::make_tuple(max_iterations > 0, curr);
|
return std::make_tuple(max_iterations > 0, curr);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user