diff --git a/listener.ts b/listener.ts index 50a9a2d..a202371 100644 --- a/listener.ts +++ b/listener.ts @@ -1,9 +1,18 @@ import { run } from "@ludus/ludus-js-pure" import { unlinkSync, readFileSync } from "node:fs" +function random_port () { + return Math.floor(Math.random() * 10000) +} + export async function listen () { - const id = Math.floor(Math.random() * 1000) + 5000 - const unix_socket = `/tmp/ludus-${id}.sock` + let id = random_port() + let unix_socket = `/tmp/ludus-${id}.sock` + // make sure the socket path isn't already taken + while (await Bun.file(unix_socket).exists()) { + id = random_port() + unix_socket = `/tmp/ludus-${id}.sock` + } const repl_file_path = ".lrepl" const repl_info = { unix_socket } const repl_file = Bun.file(repl_file_path)