In order to chain asynchronous operations and avoid a callback hell, Vala supports the yield
statement.
Used with an asynchronous invocation, it will pause the current coroutine until the call is completed and extract the result.
Used alone, yield
pause the current coroutine until it's being woken up by invoking its source callback.
public async int foo_async () {
yield; // pause the coroutine
Timeout.add_seconds (5, bar_async.callback); // wakeup in 5 seconds
return ret + 10;
}
public async int bar_async () {
var ret = yield foo_async ();
}