Resume execution for at most `time_budget` wall-clock time. Time is checked periodically, so execution may overshoot the requested time budget before returning [`ExecProgress::Suspended`] (currently time is checked every 128 instructions, but this may change in the future). Returns [`ExecProgress::Suspended`] when the budget is exhausted, or [`ExecProgress::Completed`] with the final values once
(
&mut self,
time_budget: crate::std::time::Duration,
)
| 474 | /// currently blocking. They do not suspend and later resume the host |
| 475 | /// function in the middle of the nested call. |
| 476 | pub fn resume_with_time_budget( |
| 477 | &mut self, |
| 478 | time_budget: crate::std::time::Duration, |
| 479 | ) -> Result<ExecProgress<Vec<WasmValue>>> { |
| 480 | let FuncExecutionState::Running { exec_state, root_func_addr } = &mut self.state else { |
| 481 | let FuncExecutionState::Completed { result } = &mut self.state else { |
| 482 | unreachable!("invalid function execution state") |
| 483 | }; |
| 484 | return match result.take() { |
| 485 | Some(res) => Ok(ExecProgress::Completed(res)), |
| 486 | None => Err(Error::other("execution already completed")), |
| 487 | }; |
| 488 | }; |
| 489 | |
| 490 | self.store.enter_execution()?; |
| 491 | let result = InterpreterRuntime::exec_with_time_budget(self.store, exec_state.callframe, time_budget); |
| 492 | self.store.exit_execution(); |
| 493 | |
| 494 | match result? { |
| 495 | crate::interpreter::ExecState::Completed => { |
| 496 | let result_ty = self.store.state.get_func(*root_func_addr).ty().clone(); |
| 497 | self.state = FuncExecutionState::Completed { result: None }; |
| 498 | Ok(ExecProgress::Completed(collect_call_results(&mut self.store.value_stack, &result_ty)?)) |
| 499 | } |
| 500 | crate::interpreter::ExecState::Suspended(callframe) => { |
| 501 | exec_state.callframe = callframe; |
| 502 | Ok(ExecProgress::Suspended) |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | fn validate_call_params(func_ty: &FuncType, params: &[WasmValue]) -> Result<()> { |