Skip to content

Commit

Permalink
move logic out of async block
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-finch-tezos committed Oct 18, 2023
1 parent 8b4c4fe commit 899dff5
Showing 1 changed file with 22 additions and 29 deletions.
51 changes: 22 additions & 29 deletions jstz_cli/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,38 +104,31 @@ pub fn exec(self_address: Option<String>) -> Result<()> {
fn evaluate(input: &str, rt: &mut Runtime, hrt: &mut (impl HostRuntime + 'static)) {
let rt_output = runtime::with_host_runtime(hrt, || -> JsResult<JsValue> {
let value = rt.eval(Source::from_bytes(input))?;

jstz_core::future::block_on(rt.run_event_loop());

Ok(value)
jstz_core::future::block_on(async {
rt.run_event_loop().await;
rt.resolve_value(&value).await
})
});

jstz_core::future::block_on(async move {
match rt_output {
Ok(mut res) => {
if res.is_promise() {
if let Ok(promise_result) = rt.resolve_value(&res).await {
res = promise_result;
}
}
if !res.is_undefined() {
println!(
"{}",
res.to_string(&mut rt.context())
.unwrap()
.to_std_string_escaped()
);
if let Err(err) =
rt.global_object()
.set(js_string!("_"), res, false, rt.context())
{
println!("Couldn't set '_' property: {err}");
}
}
match rt_output {
Ok(res) => {
if !res.is_undefined() {
println!(
"{}",
res.to_string(&mut rt.context())
.unwrap()
.to_std_string_escaped()
);
}
Err(e) => {
eprintln!("Uncaught {e}")
if let Err(err) =
rt.global_object()
.set(js_string!("_"), res, false, rt.context())
{
println!("Couldn't set '_' property: {err}");
}
}
});
Err(e) => {
eprintln!("Uncaught {e}")
}
}
}

0 comments on commit 899dff5

Please sign in to comment.