ludus-repl/sender.ts
Scott Richmond 735e807488 Fix conflict in listener.ts
Improve matters

Complete first version.
2023-12-26 22:36:37 -05:00

32 lines
683 B
TypeScript

export async function send() {
const repl_file = Bun.file("./.lrepl")
let repl_info
try {
repl_info = await repl_file.json()
} catch (e) {
console.log("No .lrepl file found.")
process.exit(1)
}
const port = repl_info.port
const session = repl_info.session
const socket = await Bun.connect({
hostname: "localhost",
port,
socket: {
data: () => process.exit()
}
})
for await (const input of Bun.stdin.stream()) {
const chunk = Buffer.from(input).toString("utf-8")
const payload = {source: chunk, session}
// console.log("Sending:", payload)
// console.log(`To: ${port}`)
socket.write(JSON.stringify(payload))
socket.end()
process.exit()
}
}