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

Function waitForFile

src/daemon/client.ts:29–68  ·  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

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

Callers 2

startDaemonFunction · 0.85
stopDaemonFunction · 0.85

Calls 3

checkFunction · 0.85
resolveFunction · 0.85
rejectFunction · 0.85

Tested by

no test coverage detected