diff options
author | Aylur <[email protected]> | 2024-08-22 02:14:36 +0200 |
---|---|---|
committer | Aylur <[email protected]> | 2024-08-22 02:14:50 +0200 |
commit | 24af00f6a7f624feda4b6aaceb4c5b0fa6f536d6 (patch) | |
tree | 11fdac0f3031a991b32b12ff76f5f96adaf4848d /src/variable.vala | |
parent | 6dd5200fa30c48e1cd9a2f820c62c54b0974c925 (diff) |
feat: async Process.exec
the exec_async function was not truly async but a signal based one
Diffstat (limited to 'src/variable.vala')
-rw-r--r-- | src/variable.vala | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/variable.vala b/src/variable.vala index e1d6414..c7edb16 100644 --- a/src/variable.vala +++ b/src/variable.vala @@ -141,20 +141,26 @@ public class Variable : VariableBase { }, Priority.DEFAULT); } if (poll_exec != null) { - var proc = new Process.exec_asyncv(poll_exec); - proc.stdout.connect((str) => set_closure(str, poll_transform)); - proc.stderr.connect((str) => this.error(str)); - poll_id = Timeout.add(poll_interval, () => { + Process.exec_asyncv.begin(poll_exec, (_, res) => { try { - proc = new Process.exec_asyncv(poll_exec); - proc.stdout.connect((str) => set_closure(str, poll_transform)); - proc.stderr.connect((str) => this.error(str)); - return Source.CONTINUE; + var str = Process.exec_asyncv.end(res); + set_closure(str, poll_transform); } catch (Error err) { - printerr("%s\n", err.message); - poll_id = 0; - return Source.REMOVE; + this.error(err.message); } + }); + poll_id = Timeout.add(poll_interval, () => { + Process.exec_asyncv.begin(poll_exec, (_, res) => { + try { + var str = Process.exec_asyncv.end(res); + set_closure(str, poll_transform); + } catch (Error err) { + this.error(err.message); + Source.remove(poll_id); + poll_id = 0; + } + }); + return Source.CONTINUE; }, Priority.DEFAULT); } } |