Vala async retry pattern: re-invoking a GError-throwing method without duplicating writes
0 reputation · 14 Jul 2026, 08:11 UTC
0 reputation · 14 Jul 2026, 08:11 UTC
I have a Vala async method (compiled against Vala 0.44+ / GLib GTask) that performs a write, e.g. appending a record to a file or sending a request. On failure it throws a GError, which the caller catches via try/catch around the yield. I want to retry the operation a bounded number of times, but only when the write provably did not happen, so a retry never produces a duplicate record.
Since GTask finalizes its resources when it completes, each retry presumably needs a fresh invocation of the async method rather than reusing any task state. What is unclear is the error semantics: when the async method throws, there is no documented guarantee about how far the underlying operation progressed. The error may have been raised before the write, after a partial write, or after a complete write whose success signal was lost.
The compiler does not enforce anything about shared mutable state between attempts, so idempotency has to come from my own design (sequence numbers, unique keys, or pre-write checks).
GError from a yield and simply calling the same async method again the intended retry pattern, or are there pitfalls in how continuations and the main context are scheduled across attempts?A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.