diff options
author | Casper Beyer <caspervonb@pm.me> | 2020-10-18 22:19:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-18 16:19:47 +0200 |
commit | b33e8d5d427934544fa6e0de44df8793aae63c9d (patch) | |
tree | cc3206c8e00608feabaa7fa5a8021595f4409b70 /cli/repl.rs | |
parent | c1c760130406405c8fde9a74bd88c62ca721967b (diff) |
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.
Diffstat (limited to 'cli/repl.rs')
-rw-r--r-- | cli/repl.rs | 48 |
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"); |