mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 10:33:54 +00:00
REPL unblock event loop AND fix REPL setTimeout fire problems
This commit is contained in:
parent
89096c9210
commit
09aa9b9698
3 changed files with 26 additions and 10 deletions
19
js/repl.ts
19
js/repl.ts
|
@ -28,7 +28,7 @@ function startRepl(historyFile: string): number {
|
|||
}
|
||||
|
||||
// @internal
|
||||
export function readline(rid: number, prompt: string): string {
|
||||
export async function readline(rid: number, prompt: string): Promise<string> {
|
||||
const builder = flatbuffers.createBuilder();
|
||||
const prompt_ = builder.createString(prompt);
|
||||
msg.ReplReadline.startReplReadline(builder);
|
||||
|
@ -36,8 +36,11 @@ export function readline(rid: number, prompt: string): string {
|
|||
msg.ReplReadline.addPrompt(builder, prompt_);
|
||||
const inner = msg.ReplReadline.endReplReadline(builder);
|
||||
|
||||
// TODO use async?
|
||||
const baseRes = dispatch.sendSync(builder, msg.Any.ReplReadline, inner);
|
||||
const baseRes = await dispatch.sendAsync(
|
||||
builder,
|
||||
msg.Any.ReplReadline,
|
||||
inner
|
||||
);
|
||||
|
||||
assert(baseRes != null);
|
||||
assert(msg.Any.ReplReadlineRes === baseRes!.innerType());
|
||||
|
@ -49,7 +52,7 @@ export function readline(rid: number, prompt: string): string {
|
|||
}
|
||||
|
||||
// @internal
|
||||
export function replLoop(): void {
|
||||
export async function replLoop(): Promise<void> {
|
||||
window.deno = deno; // FIXME use a new scope (rather than window).
|
||||
|
||||
const historyFile = "deno_history.txt";
|
||||
|
@ -58,7 +61,7 @@ export function replLoop(): void {
|
|||
let code = "";
|
||||
while (true) {
|
||||
try {
|
||||
code = readBlock(rid, "> ", " ");
|
||||
code = await readBlock(rid, "> ", " ");
|
||||
} catch (err) {
|
||||
if (err.message === "EOF") {
|
||||
break;
|
||||
|
@ -91,14 +94,14 @@ function evaluate(code: string): void {
|
|||
}
|
||||
}
|
||||
|
||||
function readBlock(
|
||||
async function readBlock(
|
||||
rid: number,
|
||||
prompt: string,
|
||||
continuedPrompt: string
|
||||
): string {
|
||||
): Promise<string> {
|
||||
let code = "";
|
||||
do {
|
||||
code += readline(rid, prompt);
|
||||
code += await readline(rid, prompt);
|
||||
prompt = continuedPrompt;
|
||||
} while (parenthesesAreOpen(code));
|
||||
return code;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue