import { createServer } from "node:net";
//#region src/browser/free-port.ts
/** Ask the OS for an unused TCP port on 127.0.0.1. */
async function pickFreePort() {
	return new Promise((resolve, reject) => {
		const server = createServer();
		server.listen(0, "127.0.0.1", () => {
			const address = server.address();
			if (!address || typeof address === "string") {
				server.close();
				reject(/* @__PURE__ */ new Error("Failed to pick free port"));
				return;
			}
			const port = address.port;
			server.close(() => resolve(port));
		});
		server.on("error", reject);
	});
}
//#endregion
export { pickFreePort };

//# sourceMappingURL=free-port.js.map