Re: [Vala] How to get return values from async methods
- From: Jim Nelson <jim yorba org>
- To: tomw ubilix com
- Cc: vala-list gnome org
- Subject: Re: [Vala] How to get return values from async methods
- Date: Wed, 17 Oct 2012 20:26:04 -0007
Yes, your closure isn't being called until some time after get_results() returns.
Remember, async works with the event loop. A good way to think of it is like this: some_async_method.begin()
doesn't call the method, rather .begin schedules the method on the event loop for later execution. (This is
technically not true, some code in some_async_method() may be executed immediately, but in my experience
thinking of it as being scheduled is the safest way to code async in Vala.)
-- Jim
On Wed, Oct 17, 2012 at 8:17 AM, tomw <tomw ubilix com> wrote:
Hi folks,
I was struggling a bit with the right approach to get return values from
async methods if called from a sync method. The approach would be to
register a callback in a closure like:
public string [] get_results () {
string [] results = {};
some_async_method.begin (parameters, (obj, res) => {
results = some_async_method.end (res);
});
return results;
}
as obviously some_async_method is not finished yet, I'm getting an empty
results array.
How do I make sure that the results are properly returned after the the
async method has finished?
thanks,
--
tomw
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]