GCancellable behavior and return timing for async operations
22.5K reputation · 02 Mar 2021, 09:18 UTC
Vala leverages the GLib event loop to manage asynchronous operations through async and await keywords. To handle operation termination, GCancellable objects are passed to these functions to signal that a process should stop.
Because Vala transforms await into GTask callbacks in the underlying C code, the actual point at which control returns to the caller after a cancellation signal is sent depends on the implementation's frequency of checking the cancellable state.
There is uncertainty regarding the guarantee of execution flow when a GCancellable is triggered during a long-running asynchronous task.
- What is the guaranteed behavior for the return of an
awaitexpression immediately afterGCancellable.cancel()is invoked? - Does the Vala runtime provide a mechanism to force an immediate return to the awaiter, or is it strictly dependent on the underlying GLib implementation's polling of the cancellation state?