Skip to content

Commit

Permalink
use async API
Browse files Browse the repository at this point in the history
  • Loading branch information
danvk committed Jan 17, 2024
1 parent 522031c commit 80d5998
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { once } from "node:events";
import * as fs from "node:fs/promises";
import { createInterface } from "node:readline";

Expand Down Expand Up @@ -25,7 +26,8 @@ export function resetErrors() {
hadRuntimeError = false;
}

export function runPrompt(interpreter: Interpreter) {
export async function runPrompt(interpreter: Interpreter) {
// https://nodejs.org/api/readline.html#example-tiny-cli
const rl = createInterface({
input: process.stdin,
output: process.stdout,
Expand All @@ -42,6 +44,8 @@ export function runPrompt(interpreter: Interpreter) {
resetErrors();
rl.prompt();
});

await once(rl, "close");
}

let hadError = false;
Expand Down Expand Up @@ -116,6 +120,6 @@ export async function main() {
if (args.length == 1) {
await runFile(interpreter, args[0]);
} else {
runPrompt(interpreter);
await runPrompt(interpreter);
}
}

0 comments on commit 80d5998

Please sign in to comment.