Re: [Vala] Bug in async methods?



I think you would need to work with the Vala team to get something like this landed.  Part of the solution 
might be to look at the other back-ends that Vala supports (i.e. Posix), although I think those are kept in a 
separate branch and not supported in the main distribution.

However, I suspect you're trying to do something specific for your project, and it's best if you built a 
custom system for doing these async operations.  You might be able to package it up into a separate library, 
if it's generic enough.

-- Jim

On Mon, Oct 22, 2012 at 4:15 PM, rastersoft <raster rastersoft com> wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I've been watching the source code generated by Vala and the key is here:

    _data_->result = 1;
    if (_data_->_state_ == 0) {
        g_simple_async_result_complete_in_idle (_data_->_async_result);
    } else {
        g_simple_async_result_complete (_data_->_async_result);
    }

What do you think about a decorator or something similar to allow to use async functions without main loop, 
just using always g_simple_async_result_complete() in those cases?

I ask this because I'm using Vala to do simulations, using an architecture similar to SimPy (this is, based 
on async methods) and it would be much more convenient to be able to work that way in those cases.

El 23/10/12 00:22, Jim Nelson escribió:
It would take me a bit of time
      to explain async (I've thought about blogging about it), but the
      short answer is: Vala's async and yield keywords are designed to
      use MainLoop to schedule code execution.

      >

      > You don't *have* to use them to do asynchronous work, but
      they are certainly convenient.

      >

      > -- Jim

      >

      > On Mon, Oct 22, 2012 at 3:19 PM, rastersoft
      <raster rastersoft com> wrote:

      >

      > Yes, you are right: I created a main loop, called run(), and
      the callback got called.

      >

      > Anyway, I don't understand why is not possible to ensure that
      the end callback gets called even without a main loop :?

      >

      > Thanks!

      >

      > El 23/10/12 00:03, Jim Nelson escribió:

      > > For async to work properly, you

      > must run the GLib MainLoop. MainLoop is where your async
      closure

      > for test_function.begin() is called. It's where all callbacks
      are

      > scheduled, actually.

      >

      >

      >

      > > The only reason this works is that in the case of
      DO_YIELD

      > you stash the test_function.callback and then call it back.
      That's

      > why you're seeing "End callback called 1".

      >

      >

      >

      > > A better way to do this is to (a) get rid of
      ext_callback and

      > (b) call "new GLib.MainLoop().run()" right before the "return
      0"

      > in main(). Without actually modifying the code (i.e. I'm
      doing

      > this off the top of my head), that should work.

      >

      >

      >

      > > -- Jim

      >

      >

      >

      > > On Mon, Oct 22, 2012 at 2:47 PM, rastersoft

      > <raster rastersoft com> wrote:

      >

      >

      >

      > > Hi all:

      >

      >

      >

      > > I was working with async methods, and found something
      odd: if

      > I call an

      >

      > > async method, but, for whatever reason, I never call
      YIELD

      > inside, the

      >

      > > end callback function is never called.

      >

      >

      >

      > > I attach an example: by compiling it with

      >

      >

      >

      > > valac -D DO_YIELD -o test_async test_async.vala
      --pkg=gio-2.0

      >

      >

      >

      > > will do a YIELD inside the async function. But when
      compiled

      > with

      >

      >

      >

      > > valac -o test_async test_async.vala --pkg=gio-2.0

      >

      >

      >

      > > will not. In the former case you can see how "End
      callback

      > called 1" is

      >

      > > printed, because the callback for the end is called; but
      in

      > the later,

      >

      > > it's not printed.

      >

      >

      >

      > > Is that a bug? If not, why does it work that way?

      >

      >

      >

      > > Thanks.

      >

      >

      >

      >

      >

      >

      >

      >

      >

      >

      >

      >

- -- 
Nos leemos
                 RASTER    (Linux user #228804)
raster rastersoft com              http://www.rastersoft.com

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iEYEARECAAYFAlCF06UACgkQXEZvyfy1ha/LHwCfZyN6VrCTRoBo+qj/F5ueyCM1
9MMAoM/a1bpZviM5ktwhpPRCHJKtSToL
=62sR
-----END PGP SIGNATURE-----




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