Re: [Vala] calling delegate from async



On Fri, Oct 23, 2009 at 15:31:53 +0200, pHilipp Zabel wrote:
Hi,

I'd like to call a delegate function from an async function, like this:

class AsyncDelegate {
        delegate void TestFunc ();

        void test_func () {
                print ("delegate\n");
        }

        async void test_async (TestFunc f) {

Can you try it with

    async void test_async (owned TestFunc f) {

?

                print ("async enter\n");
                Idle.add (test_async.callback);
                yield;
                f ();
                print ("async leave\n");
        }

        static int main (string[] args) {
                var loop = new GLib.MainLoop (null, false);
                var app = new AsyncDelegate ();

                app.test_async.begin (app.test_func);
                print ("loop\n");
                loop.run ();

                return 0;
        }
}

But Vala 0.7.7 doesn't like that at all:

** (valac:7627): CRITICAL **: vala_data_type_get_value_owned:
assertion `self != NULL' failed
/home/ph5/vala/async-delegate/async-delegate.vala.c:44: error:
expected specifier-qualifier-list before Б─≤AsyncDelegateTestFuncБ─≥
[...]
Compilation failed: 1 error(s), 0 warning(s)

It can't work with unowned delegate (add 'owned' as mentioned above), because
vala can't guarantee the invocant will be valid by the time the async
function gets to call it.

However, vala should report an understandable error, so filing a bug would be
appropriate.

When I turn test_async into a sync function again, it works just fine.

There the delegate invocant does not get a chance to go away while test_async
runs, so the unowned delegate works fine.

Trying to turn TestFunc into an async delegate function (and call it
with yield f ()) on the other hand, seems to be even more critical:

I don't think async delegates were ever supposed to be supported. Given that
async function is really two functions an async delegate would be pretty
complicated.

That said, vala should give some sane error message.

** (valac:7707): CRITICAL **: vala_data_type_get_value_owned:
assertion `self != NULL' failed
** (valac:7707): CRITICAL **:
vala_ccode_expression_statement_construct: assertion `expr != NULL'
failed
** (valac:7707): CRITICAL **: vala_ccode_fragment_append: assertion
`node != NULL' failed
/home/ph5/vala/async-delegate/async-delegate.vala.c:52: error:
expected specifier-qualifier-list before Б─≤AsyncDelegateTestFuncБ─≥
[...]
Compilation failed: 1 error(s), 0 warning(s)

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



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