Allow ref our out parameters with async in scope
@malureau
Submitted by Marc-André Lureau Link to original bug (#681136)
Description
It is currently not possible to use:
yield exec (argv, null, out standard_output);
public delegate void RunInThreadFunc () throws GLib.Error;
public async void run_in_thread (RunInThreadFunc func, Cancellable? cancellable = null) throws GLib.Error {
GLib.Error e = null;
GLib.g_io_scheduler_push_job ((job, cancellable) => {
try {
func ();
} catch (GLib.Error err) {
e = err;
}
job.send_to_mainloop (() => {
run_in_thread.callback ();
return false;
});
return false;
}, GLib.Priority.DEFAULT, cancellable);
yield;
if (e != null)
throw e;
}
public async void exec (string[] argv,
Cancellable? cancellable,
out string? standard_output = null,
out string? standard_error = null) throws GLib.Error {
yield run_in_thread (() => {
exec_sync (argv, standard_output, out standard_error);
}, cancellable);
}
I use the following workaround:
public async void exec (string[] argv,
Cancellable? cancellable,
out string? standard_output = null,
out string? standard_error = null) throws GLib.Error {
string std_output = "";
string std_error = "";
yield run_in_thread (() => {
exec_sync (argv, out std_output, out std_error);
}, cancellable);
standard_output = std_output;
standard_error = std_error;
}
09:20 < juergbi>
elmarco: we should be able to add support for this
09:20 < juergbi>
the check against ref/out was probably added before we had async
methods
09:21 < juergbi>
assuming vala knows that run_in_thread argument will run in-scope