From 8cd4f0b47bd0d153e7d738a22ab7a6f3b2d29d34 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Tue, 26 Dec 2023 17:54:34 -0500 Subject: [PATCH] Change listener.ts --- listener.ts | 55 +++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/listener.ts b/listener.ts index 0917e7b..ce342be 100644 --- a/listener.ts +++ b/listener.ts @@ -1,35 +1,40 @@ import { run } from "@ludus/ludus-js-pure" -const port = Math.floor((Math.random() * 1000) + 50000) +async function listen() { + const port = Math.floor((Math.random() * 1000) + 50000) -const repl_info = { port } + const repl_info = { port } -const repl_file = Bun.file("./.lrepl") + const repl_file = Bun.file("./.lrepl") -await Bun.write(repl_file, JSON.stringify(repl_info)) + await Bun.write(repl_file, JSON.stringify(repl_info)) -console.log(`Ludus REPL listening on localhost:${port}`) + console.log(`Ludus REPL listening on localhost:${port}`) -Bun.listen({ - hostname: "localhost", - port, - socket: { - data: (socket, data) => { - const source = data.toString("utf-8") - const result = run(source) - const msgs = result.console - for (const msg of msgs) { - console.log(msg) - } - if (!result.errors) console.log(result.result) - else { - console.log("Ludus had some errors:") - console.log(result.errors) - } - }, - error: (socket, error) => { console.log(error); socket.end() } - } -}) + Bun.listen({ + hostname: "localhost", + port, + socket: { + data: (socket, data) => { + console.log("I got data!") + const source = data.toString("utf-8") + const result = run(source) + const msgs = result.console + for (const msg of msgs) { + console.log(msg) + } + if (!result.errors) console.log(result.result) + else { + console.log("Ludus had some errors:") + console.log(result.errors) + } + }, + error: (socket, error) => { console.log(error); socket.end() } + } + }) +} + +await listen()