how to set timeout when execute new process? #259
Unanswered
itech001
asked this question in
Help needed
Replies: 1 comment 2 replies
-
E.g. #!/usr/bin/env zx
const timeout = (p, ms) => {
return new Promise((resolve, reject) => {
p.then(resolve).catch(reject);
setTimeout(() => {
p.kill()
reject(new Error('timeout'));
}, ms);
})
}
const output = await timeout($`sleep 5; ls`, 2000)
console.log(output) output: § zx timeout.mjs
$ sleep 5; ls
file:///.../timeout.mjs:8
reject(new Error('timeout'));
^
Error: timeout
at Timeout._onTimeout (file:///.../timeout.mjs:8:14)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7) Changing the command to $ sleep 2; false
Error:
at file:///Users/mbl/timeout.mjs:13:31
exit code: 1 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
how to set timeout when execute new process?
Beta Was this translation helpful? Give feedback.
All reactions