Re: [Vala] Combining async methods with external processes



Hi,
                   في ح، 21-11-2010 عند 16:03 +1030 ، كتب James Moschou:
Here's an incredibly pared back version of what I have:


class Task : Object {
    Pid _pid;
    Source _source;
    public async void run_async () {
        try {
            Process.spawn_async_with_pipes (null,
                                            {"whois", "www.google.com"},
                                            null,
                                            SpawnFlags.SEARCH_PATH |
SpawnFlags.DO_NOT_REAP_CHILD,
                                            null,
                                            out _pid,
                                            null,
                                            null,
                                            null);

            _source = new GLibFixes.ChildWatchSource (_pid);
            _source.attach (null);
            _source.set_callback (run_async.callback);

Just replace the three above lines with:
              ChildWatch.add (_pid, (pid, status) => run_async.callback());
and it won't segfault (and won't need fixes in GLib bindings either :-)

            yield;
        }
        catch (Error error) {
            stderr.printf ("%s\n", error.message);
        }
        Process.close_pid (_pid);
    }
}

HTH,
Abderrahim




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