summaryrefslogtreecommitdiff
path: root/cli/repl.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/repl.rs')
-rw-r--r--cli/repl.rs48
1 files changed, 26 insertions, 22 deletions
diff --git a/cli/repl.rs b/cli/repl.rs
index 3540b422b..2e41b0565 100644
--- a/cli/repl.rs
+++ b/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");