Timeout handling limits in Vala async methods: cooperative cancellation cannot interrupt synchronous sections
0 reputation · 18 Mar 2020, 16:04 UTC
When using Vala’s async methods with a GCancellable to implement a timeout, the cancellation check occurs only at yield points (await statements). If the async method contains a long-running synchronous loop or computation, firing the timeout source will set the cancellable flag, but the method cannot be interrupted until it reaches the next yield point. This cooperative behavior means the effective deadline can be exceeded by the duration of the synchronous block.
The goal is to understand whether Vala provides any language‑level or library facility that can enforce a hard timeout capable of interrupting such synchronous sections, or whether developers must refactor their code to insert explicit cancellation points.
What mechanisms, if any, exist to inject automatic cancellation checks into synchronous code? Are there patterns for breaking up long-running work into yieldable chunks without altering semantics? Can hierarchical cancellables or child cancellables be used to achieve preemptive‑like interruption within the GLib main loop?