summaryrefslogtreecommitdiff
path: root/gjs/src/process.ts
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-08-22 02:14:36 +0200
committerAylur <[email protected]>2024-08-22 02:14:50 +0200
commit24af00f6a7f624feda4b6aaceb4c5b0fa6f536d6 (patch)
tree11fdac0f3031a991b32b12ff76f5f96adaf4848d /gjs/src/process.ts
parent6dd5200fa30c48e1cd9a2f820c62c54b0974c925 (diff)
feat: async Process.exec
the exec_async function was not truly async but a signal based one
Diffstat (limited to 'gjs/src/process.ts')
-rw-r--r--gjs/src/process.ts29
1 files changed, 22 insertions, 7 deletions
diff --git a/gjs/src/process.ts b/gjs/src/process.ts
index 577ad99..c5329e2 100644
--- a/gjs/src/process.ts
+++ b/gjs/src/process.ts
@@ -1,4 +1,4 @@
-import { Astal, GLib } from "./imports.js"
+import { Astal } from "./imports.js"
type Args<Out = void, Err = void> = {
cmd: string | string[]
@@ -24,7 +24,7 @@ export function subprocess(
export function subprocess(
argsOrCmd: Args | string | string[],
onOut: (stdout: string) => void = print,
- onErr: (stderr: string) => void = console.log,
+ onErr: (stderr: string) => void = printerr,
) {
const { cmd, err, out } = args(argsOrCmd, onOut, onErr)
const proc = Array.isArray(cmd)
@@ -44,11 +44,26 @@ export function exec(cmd: string | string[]) {
}
export function execAsync(cmd: string | string[]): Promise<string> {
- const proc = Array.isArray(cmd)
- ? Astal.Process.exec_asyncv(cmd)
- : Astal.Process.exec_async(cmd)
return new Promise((resolve, reject) => {
- proc.connect("stdout", (_, out: string) => resolve(out))
- proc.connect("stderr", (_, err: string) => reject(err))
+ if (Array.isArray(cmd)) {
+ Astal.Process.exec_asyncv(cmd, (_, res) => {
+ try {
+ resolve(Astal.Process.exec_asyncv_finish(res))
+ }
+ catch (error) {
+ reject(error)
+ }
+ })
+ }
+ else {
+ Astal.Process.exec_async(cmd, (_, res) => {
+ try {
+ resolve(Astal.Process.exec_finish(res))
+ }
+ catch (error) {
+ reject(error)
+ }
+ })
+ }
})
}