[Vala] question on async methods



I would like to pose a tricky question on the use of async in Vala.
I pasted a vala file here: http://pastebin.com/uS5dxNHy
There you find also the command to compile and the output of the run.

Please bear with me while I try to explain what I want to prove with this app.

When I launch the async method method1 with begin() it starts. The
method executes a bare yield and the flow passes back to main. The
remaining part of method1 will never complete.
What this shows is that if a async method yields in the middle of its
code without registering its continuation anywhere it won't ever
complete.

When I launch the async method method2 with begin() it starts. The
method registers its continuation with Idle.add, then executes a bare
yield and the flow passes back to main. When, at the end, main runs a
MainLoop the method2 will complete its code.
What this shows is that if a method registers its continuation with
Glib.Idle then it will be rescheduled by GLib.MainLoop.

Methods method3 and method4 show the same behavior of method1 and
method2. They yield to another async method (method3bis and
method4bis) and this will execute a bare yield. Only the one that
registers its continuation with Glib.Idle will complete its operation
and make the async caller happy too.

The sequence of messages in the output shows that MainLoop will
schedule the registered continuations in the order that they have been
registered with Idle.add.

When I launch the async method method5 with begin() it starts. It
yields to another async method (method6) which does something but
never [explicitly] yields.
After method6 finishes, the flow passes back to main. The remaining
part of method5 *will* be scheduled back by MainLoop.
Note also that when MainLoop runs the remaining part of method5 is
rescheduled immediately, not after method2 and method4.

What I guess is that:
 . when a async method never calls a yield, then it is implicit
    a yield at the end of the method
 . the implicit continuation is implicitly registered with the MainLoop
    perhaps with a higher priority than Idle.

Is my interpretation correct?
Is this behavior wanted?

I find it particularly annoying because I would prefer to implement my
own scheduler instead of relying on MainLoop.

Regards
--Luca Dionisi



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