FileWriteRetry.h header
#include <ew/app/FileWriteRetry.h>
Namespace ew::app
FileWriteRetryPolicy struct
struct ew::app::FileWriteRetryPolicy
Policy for retrying a transient file-write failure. A project save can fail momentarily when another program holds the same file – the desktop app editing the project, a sync client (OneDrive/Dropbox), or antivirus scanning it. Such locks usually clear within a few hundred milliseconds, so a bounded retry with a short backoff turns a transient failure into a success. The attempt count is bounded and the backoff is capped, so a genuinely permanent failure (an unwritable path, a full disk) still returns promptly rather than spinning.
Members
int ew::app::FileWriteRetryPolicy::maxAttempts = 5
The maximum number of attempts (the first try plus retries). At least one.
std::chrono::milliseconds ew::app::FileWriteRetryPolicy::initialBackoff {40}
The wait before the first retry. Each subsequent wait doubles, capped at maxBackoff.
std::chrono::milliseconds ew::app::FileWriteRetryPolicy::maxBackoff {500}
The ceiling on the per-retry backoff, so the total wait stays bounded (~0.6 s by default).
Functions
ew::core::Result< void > ew::app::retryFileWrite(const std::function< ew::core::Result< void >()> &attempt, const FileWriteRetryPolicy &policy, const std::function< void(std::chrono::milliseconds)> &sleep)
Runs attempt, retrying up to policy.maxAttempts times while it returns an error, sleeping (via sleep) with an exponential, capped backoff between tries. Returns the first success, or the LAST error when every attempt fails. sleep is injected so tests exercise the retry logic without really waiting.
ew::core::Result< void > ew::app::retryFileWrite(const std::function< ew::core::Result< void >()> &attempt)
Convenience overload using the default policy and a real (QThread::msleep) wait. Used by the storage layer so an ordinary project save survives a brief external lock.