MCPcopy Create free account
hub / github.com/ChromeDevTools/chrome-devtools-mcp / waitForFile

Function waitForFile

src/daemon/client.ts:35–74  ·  view source on GitHub ↗

* Waits for a file to be created and populated (removed = false) or removed (removed = true).

(filePath: string, removed = false)

Source from the content-addressed store, hash-verified

33 * Waits for a file to be created and populated (removed = false) or removed (removed = true).
34 */
35function waitForFile(filePath: string, removed = false) {
36 return new Promise<void>((resolve, reject) => {
37 const check = () => {
38 const exists = fs.existsSync(filePath);
39 if (removed) {
40 return !exists;
41 }
42 if (!exists) {
43 return false;
44 }
45 try {
46 return fs.statSync(filePath).size > 0;
47 } catch {
48 return false;
49 }
50 };
51
52 if (check()) {
53 resolve();
54 return;
55 }
56
57 const timer = setTimeout(() => {
58 fs.unwatchFile(filePath);
59 reject(
60 new Error(
61 `Timeout: file ${filePath} ${removed ? 'not removed' : 'not found'} within ${FILE_TIMEOUT}ms`,
62 ),
63 );
64 }, FILE_TIMEOUT);
65
66 fs.watchFile(filePath, {interval: 500}, () => {
67 if (check()) {
68 clearTimeout(timer);
69 fs.unwatchFile(filePath);
70 resolve();
71 }
72 });
73 });
74}
75
76function delay(ms: number) {
77 return new Promise<void>(resolve => {

Callers 2

startDaemonFunction · 0.85
stopDaemonFunction · 0.85

Calls 1

checkFunction · 0.85

Tested by

no test coverage detected