Change execSync/spawnSync to async (#4123)

* WIP

* Add missing await

* Update package-lock.json
This commit is contained in:
Louis Lam
2023-11-30 16:12:04 +08:00
committed by GitHub
parent 73239d441d
commit 1708b67949
6 changed files with 23 additions and 16 deletions

View File

@@ -1,6 +1,6 @@
const { MonitorType } = require("./monitor-type");
const { UP } = require("../../src/util");
const childProcess = require("child_process");
const childProcessAsync = require("promisify-child-process");
/**
* A TailscalePing class extends the MonitorType.
@@ -38,12 +38,9 @@ class TailscalePing extends MonitorType {
*/
async runTailscalePing(hostname, interval) {
let timeout = interval * 1000 * 0.8;
let res = childProcess.spawnSync("tailscale", [ "ping", hostname ], {
let res = await childProcessAsync.spawn("tailscale", [ "ping", "--c", "1", hostname ], {
timeout: timeout
});
if (res.error) {
throw new Error(`Execution error: ${res.error.message}`);
}
if (res.stderr && res.stderr.toString()) {
throw new Error(`Error in output: ${res.stderr.toString()}`);
}