I am trying to make a async closure because I call another async function inside. Some I am trying to do something like this:
void connect_on_button_click () {
some_button.connect (() => {
var val = yield some_async_function ();
// Do something with the value...
});
}
But vala compiler gives error. So currently my solution is passing a defined async function such as:
async void on_button_click () {
var val = yield some_async_function ();
// Do something with the value...
}
void connect_on_button_click () {
some_button.connect (on_button_click);
}
But I wonder if it is possible to mark a closure as async so I don't have to create another function?
Async lambdas/closures/delegates currently aren't supported.
However if your example above reflects your actual use case then you don't actually need them, you just need to use the async_method.begin(…)
form to call the async method:
void connect_on_button_click () {
some_button.connect (() => {
some_async_function.begin();
});
}