wiggle: make the dummy executor return a trap rather than panic

when configured improperly
This commit is contained in:
Pat Hickey
2021-07-15 11:44:58 -07:00
parent f3b80ece5f
commit 6f07c76c84
2 changed files with 5 additions and 6 deletions

View File

@@ -149,7 +149,7 @@ fn generate_func(
#field_str,
move |mut caller: #rt::wasmtime_crate::Caller<'_, T> #(, #arg_decls)*| -> Result<#ret_ty, #rt::wasmtime_crate::Trap> {
let result = async { #body };
#rt::run_in_dummy_executor(result)
#rt::run_in_dummy_executor(result)?
},
)?;
}

View File

@@ -933,7 +933,7 @@ impl From<GuestError> for Trap {
}
}
pub fn run_in_dummy_executor<F: std::future::Future>(future: F) -> F::Output {
pub fn run_in_dummy_executor<F: std::future::Future>(future: F) -> Result<F::Output, Trap> {
use std::pin::Pin;
use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
@@ -941,10 +941,9 @@ pub fn run_in_dummy_executor<F: std::future::Future>(future: F) -> F::Output {
let waker = dummy_waker();
let mut cx = Context::from_waker(&waker);
match f.as_mut().poll(&mut cx) {
Poll::Ready(val) => return val,
Poll::Pending => {
panic!("Cannot wait on pending future: must enable wiggle \"async\" future and execute on an async Store")
}
Poll::Ready(val) => return Ok(val),
Poll::Pending =>
return Err(Trap::String("Cannot wait on pending future: must enable wiggle \"async\" future and execute on an async Store".to_owned()))
}
fn dummy_waker() -> Waker {