On Sat, Sep 19, 2009 at 01:41:34 +0200, Michael 'Mickey' Lauer wrote:
> > No, the call without .begin() is being deprecated.
> > 
> > >From yestarday's discussion on IRC I understood it's not generally possible
> > to collapse to synchronous call automagically. Doing it involves running
> > a (recursive) main loop until the callback is called, but this brings a lot
> > of problems like something quitting the outer loop, the nested loops being
> > quit out of order and such. Therefore it should not be done without user's
> > explicit request.
> 
> I see, am I correct then in assuming that at the end of the day this means, 
> calling an asynchronous function with out/return arguments is forbidden/will 
> not work from synchronous code?

It is allowed and works perfectly fine. Just you have to do it the manual way
-- pass a callback in and collect the return value there.

It's four lines like:

    Whatever result;
    var loop = new MainLoop();
    foo_async.begin((r) => { result = foo_async.finish(); loop.quit(); }
    loop.run();
    // do whatever you want with result here.

So it's doable, but a bit of typing and remembering how the MainLoop is run.

I can imagine a special syntax that will make vala generate this might be
accepted in future. My suggestion would be

    var result = yield sync foo_async();

This would make "sync" special only after "yield" and allow featuring
a large warning in the documentation about the pitfalls you may fall into if
you actually call it from a main loop (while this is normally used for modal
dialogs, they avoid most of the traps by blocking events from other windows).

> (Didier, please note that if that's true, then it's a strong argument in 
> favor 
> of letting vala-dbus-binding-tool emit both a sync. and an async. dbus vala 
> interface, since the async. interface is then basically useless to call from 
> synchronous code).

Yes, it should. Especially if it has a method to avoid the traps (running
a separate MainContext?).

-- 
                                                 Jan 'Bulb' Hudec <[email protected]>
_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to