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

Function freePort

e2e/src/vm/ec2.ts:209–217  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

207 ["#cloud-config", "ssh_authorized_keys:", ` - ${publicKey}`].join("\n");
208
209const freePort = (): Promise<number> =>
210 new Promise((resolve, reject) => {
211 const srv = net.createServer();
212 srv.on("error", reject);
213 srv.listen(0, "127.0.0.1", () => {
214 const port = (srv.address() as net.AddressInfo).port;
215 srv.close(() => resolve(port));
216 });
217 });
218
219const waitLocalPort = async (port: number, attempts = 40): Promise<void> => {
220 for (let i = 0; i < attempts; i++) {

Callers 1

ec2VmFunction · 0.70

Calls 4

listenMethod · 0.80
addressMethod · 0.80
closeMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected