Re: [Vala] [Async] why use .begin ?



On Sat, Sep 19, 2009 at 15:40:16 +0200, Didier Ptitjes wrote:
Jan Hudec wrote:
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();

I guess I would propose:

var result = foo_async();

We talked about that on IRC today with Jürg, and it may be possible to
implement such a thing, correctly with
g_main_context_push_thread_default() (GLib 2.21).

I didn't notice that thing -- it's indeed good tool for the job. I would
still prefer something to mark in the source that we are synchronizing an
async function. Maybe a .sync() "submethod" to match .begin() and .end() and
state clearly what is happening:

var result = foo_async.sync(...);
var result = foo_async.synchronously(...);

Whenever the main loop is running, using async functions is prefered in most
cases, so we don't want people using the synchronous variant by mistake and
than complain that their application is unresponsive.

Besides I am not sure it's completely idiotproof -- if you wrote an async
function that did something with the gui and than called it synchronized, it
could fail spectacularly or behave weirdly, because the it's run in different
main context than the gui (and the gui one is not running).

-- 
                                                 Jan 'Bulb' Hudec <bulb ucw cz>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]