pub struct UpdateCheckGuard { /* private fields */ }Expand description
A timestamp-stamp-file guard that throttles how often an application checks for updates. See the module docs for the full model and an example.
Implementations§
Source§impl UpdateCheckGuard
impl UpdateCheckGuard
Sourcepub fn new(stamp_path: impl Into<PathBuf>, interval: Duration) -> Self
pub fn new(stamp_path: impl Into<PathBuf>, interval: Duration) -> Self
Build a guard that records its last-check timestamp at stamp_path and considers a new check
due once interval has elapsed since that timestamp. The path and interval are the caller’s
choice; the file and its parent directory need not exist yet (they are created by
record_check).
Sourcepub fn should_check(&self) -> Result<bool>
pub fn should_check(&self) -> Result<bool>
Whether an update check is due: true when the stamp file is missing, holds an unparseable
timestamp, is dated in the future, or is at least interval old. See the
module docs for the exact rules. Returns Err only on a genuine IO
error reading the stamp (a missing file is not an error).
Sourcepub fn record_check(&self) -> Result<()>
pub fn record_check(&self) -> Result<()>
Record “now” as the time of the last check, so should_check returns
false until interval has elapsed. Writes to a temporary file in the stamp’s directory and
renames it into place so a concurrent reader never sees a partial write. Returns Err on an
IO failure (e.g. the directory does not exist or is not writable).