mirror of
https://github.com/denoland/deno.git
synced 2024-11-29 16:30:56 -05:00
refactor(cli/repl): extract is_closing to a function (#8015)
This extracts is closing into a function so that it can easily be used as the condition for the loop.
This commit is contained in:
parent
c1c7601304
commit
b33e8d5d42
1 changed files with 26 additions and 22 deletions
48
cli/repl.rs
48
cli/repl.rs
|
@ -217,6 +217,31 @@ async fn inject_prelude(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn is_closing(
|
||||
worker: &mut MainWorker,
|
||||
session: &mut InspectorSession,
|
||||
context_id: u64,
|
||||
) -> Result<bool, AnyError> {
|
||||
let closed = post_message_and_poll(
|
||||
worker,
|
||||
session,
|
||||
"Runtime.evaluate",
|
||||
Some(json!({
|
||||
"expression": "(globalThis.closed)",
|
||||
"contextId": context_id,
|
||||
})),
|
||||
)
|
||||
.await?
|
||||
.get("result")
|
||||
.unwrap()
|
||||
.get("value")
|
||||
.unwrap()
|
||||
.as_bool()
|
||||
.unwrap();
|
||||
|
||||
Ok(closed)
|
||||
}
|
||||
|
||||
pub async fn run(
|
||||
program_state: &ProgramState,
|
||||
mut worker: MainWorker,
|
||||
|
@ -267,7 +292,7 @@ pub async fn run(
|
|||
|
||||
inject_prelude(&mut worker, &mut session, context_id).await?;
|
||||
|
||||
loop {
|
||||
while !is_closing(&mut worker, &mut session, context_id).await? {
|
||||
let line = read_line_and_poll(&mut *worker, editor.clone()).await;
|
||||
match line {
|
||||
Ok(line) => {
|
||||
|
@ -315,27 +340,6 @@ pub async fn run(
|
|||
evaluate_response
|
||||
};
|
||||
|
||||
let is_closing = post_message_and_poll(
|
||||
&mut *worker,
|
||||
&mut session,
|
||||
"Runtime.evaluate",
|
||||
Some(json!({
|
||||
"expression": "(globalThis.closed)",
|
||||
"contextId": context_id,
|
||||
})),
|
||||
)
|
||||
.await?
|
||||
.get("result")
|
||||
.unwrap()
|
||||
.get("value")
|
||||
.unwrap()
|
||||
.as_bool()
|
||||
.unwrap();
|
||||
|
||||
if is_closing {
|
||||
break;
|
||||
}
|
||||
|
||||
let evaluate_result = evaluate_response.get("result").unwrap();
|
||||
let evaluate_exception_details =
|
||||
evaluate_response.get("exceptionDetails");
|
||||
|
|
Loading…
Reference in a new issue