On Sat, 2011-07-23 at 15:22 +0800, 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.
>
> hand
> Nor Jaidi Tuah
I assume that it is due to scoping:
async void foo (ref int i) {
yield;
i = 0;
yield;
}
int j = 1;
foo.begin (ref j);
j is on the stack but foo will access it outside scope. You can use
pointers and take care about scoping/freeing as compiler cannot do it
for you:
async void foo (int *i) {
yield;
*i = 0;
yield;
}
int j = 1;
foo.begin (&j, (obj, res) => {
foo.end (res);
assert (j == 0); // Ok - j still alive
});
Regards
signature.asc
Description: This is a digitally signed message part
_______________________________________________ vala-list mailing list [email protected] http://mail.gnome.org/mailman/listinfo/vala-list
