Re: [Vala] Need help in debugging async code



many thanks for your test and feedback.
Now I'will spend more than 2 minutes to make the fix, spending more time
understanding and testing.

I have undestand exactly way the patch if not working, and everything came
from from my mistake undestanding how vala works.

for example. When you call

 test2.begin(<params>, end_callback);

the end_callback is not executed at the end of test2 but it is called from
mainloop (if it is on state0). This is the reason way the mainloop is
mandatory for using async.

Now I have fix all, and seams working but vala does not work as before. for
example (vala async sleep):

public async void nap (uint interval, int priority = GLib.Priority.DEFAULT)
{
  GLib.Timeout.add (interval, () => {
      nap.callback ();
      return false;
    }, priority);
  yield;
}
private async void do_stuff () {
  yield nap (1000);
}
private static int main (string[] args) {
  GLib.MainLoop loop = new GLib.MainLoop ();
  do_stuff.begin ((obj, async_res) => {
      loop.quit ();
    });
  loop.run ();
  return 0;
}


does not work because loop.quit (); is executed before  loop.run ();.

so continue to work on it before send again a new patch

2016-09-24 10:33 GMT+02:00 Nor Jaidi Tuah <norjaidi tuah ubd edu bn>:


now,

_state_in_progress_ is assigned to -1 at beginning
the check if

_state_in_progress_ == _state_ is move before the switch to work in
any state.


That won't work either.

The fundamental problem is that the caller
that calls the callback (the mainloop or
whatever alternative you have in mind) must
be able to detect when the async method has
progressed to the next state. For the mainloop
solution, this is trivial. The alternative
you have in mind (that calls before yield)
must look at _state_ and _state_in_progress_;
otherwise, it may livelock.

There is no way you can solve this by tweaking
async only[1]; you must also tweak the callback caller.
I don't think the Vala community would accept that.



[1] Of course I may be wrong in this assertion.

Nice day
Nor Jaidi Tuah




PRIVILEGED/CONFIDENTIAL information may be contained in this message. If
you are neither the addressee (intended recipient) nor an authorised
recipient of the addressee, and have received this message in error, please
destroy this message (including attachments) and notify the sender
immediately. STRICT PROHIBITION: This message, whether in part or in whole,
should not be reviewed, retained, copied, reused, disclosed, distributed or
used for any purpose whatsoever. Such unauthorised use may be unlawful and
may contain material protected by the Official Secrets Act (Cap 153) of the
Laws of Brunei Darussalam. DISCLAIMER: We/This Department/The Government of
Brunei Darussalam, accept[s] no responsibility for loss or damage arising
from the use of this message in any manner whatsoever. Our messages are
checked for viruses but we do not accept liability for any viruses which
may be transmitted in or with this message.



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