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 <[email protected]> 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 
[email protected] 
https://mail.gnome.org/mailman/listinfo/vala-list 

_______________________________________________
vala-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to