Re: [Vala] Ref parameters to async methods



Nor Jaidi Tuah wrote:
Is there any technical reason why
reference parameters are not supported for async methods?

My work around to this is simply to replace
  async void foo (ref X x)  // cannot compile

with
  async void foo (ClosureX cx)
where Closure is
  class ClosureX {
     X x;
  }

But why can't the compiler do this for us?
I must be missing something.

I think the problem is that 'ref' is for both input and output, but
async methods put the input arguments into the .begin() call, and the
output arguments into the .end() call.  So where should the 'ref'
argument go?  It can't go in both places.

If you only need output, then use 'out' instead.  If you need both
input and output I think you'll have to use two arguments.

As the other poster said, the scope containing the variable you 'ref'
in the call will probably have completely gone by the time it is
written to, so (if it were allowed) you'd risk crashing your app due
to corrupting the stack by using 'ref' with async.

Jim

-- 
 Jim Peters                  (_)/=\~/_(_)                 jim uazu net
                          (_)  /=\  ~/_  (_)
 UazĂș                  (_)    /=\    ~/_    (_)                http://
 in Peru            (_) ____ /=\ ____ ~/_ ____ (_)            uazu.net



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