-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwatch.ts
More file actions
40 lines (35 loc) · 899 Bytes
/
watch.ts
File metadata and controls
40 lines (35 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import fs from "node:fs";
export const waitInstall = (
path: string,
timeoutSec: number = 10 * 60,
checkIntervalSec = 5,
): Promise<void> => {
return new Promise((resolve, reject) => {
const resetTimers = () => {
clearInterval(watchId);
clearTimeout(rejectId);
};
const rejectId = setTimeout(() => {
clearTimeout(rejectId);
resetTimers();
reject(`Install timed-out: ${path}`);
}, timeoutSec * 1000);
const watchId = setInterval(() => {
fs.access(path, fs.constants.F_OK, (err) => {
if (err === null) {
// file exists
resetTimers();
resolve();
return;
}
if (err.code !== "ENOENT") {
// unexpected error
resetTimers();
reject(err);
return;
}
// file not found
});
}, checkIntervalSec * 1000);
});
};