MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / waitLocalPort

Function waitLocalPort

e2e/src/vm/ec2.ts:219–236  ·  view source on GitHub ↗
(port: number, attempts = 40)

Source from the content-addressed store, hash-verified

217 });
218
219const waitLocalPort = async (port: number, attempts = 40): Promise<void> => {
220 for (let i = 0; i < attempts; i++) {
221 const ok = await new Promise<boolean>((resolve) => {
222 const sock = net.connect({ host: "127.0.0.1", port }, () => {
223 sock.destroy();
224 resolve(true);
225 });
226 sock.on("error", () => resolve(false));
227 sock.setTimeout(1000, () => {
228 sock.destroy();
229 resolve(false);
230 });
231 });
232 if (ok) return;
233 await sleep(500);
234 }
235 throw new Error(`tunnel local port ${port} never came up`);
236};
237
238export const ec2Vm = (os: VmOs, arch: VmArch = "x64"): VmProvider => ({
239 os,

Callers 1

ec2VmFunction · 0.70

Calls 5

sleepFunction · 0.90
setTimeoutMethod · 0.80
connectMethod · 0.65
destroyMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected