MCPcopy Create free account
hub / github.com/cloudflare/computer / waitForHTTPOK

Function waitForHTTPOK

packages/computerd/src/cli/computerd.test.ts:429–448  ·  view source on GitHub ↗
(url, child, output, timeoutMs = 5_000)

Source from the content-addressed store, hash-verified

427}
428
429async function waitForHTTPOK(url, child, output, timeoutMs = 5_000) {
430 const started = Date.now();
431
432 while (Date.now() - started < timeoutMs) {
433 if (child.exitCode !== null) {
434 throw new Error(`computerd exited before becoming ready: ${child.exitCode}\n${output()}`);
435 }
436
437 try {
438 const response = await request(url);
439 if (response.statusCode === 200) return;
440 } catch (error) {
441 if (!isConnectionError(error)) throw error;
442 }
443
444 await delay(50);
445 }
446
447 throw new Error(`timed out waiting for ${url}\n${output()}`);
448}
449
450function request(url) {
451 return new Promise((resolve, reject) => {

Callers 1

startComputerdFunction · 0.85

Calls 3

requestFunction · 0.85
isConnectionErrorFunction · 0.85
delayFunction · 0.85

Tested by

no test coverage detected