MCPcopy Create free account
hub / github.com/explodingcamera/tinywasm / run_with_time_budget

Method run_with_time_budget

crates/tinywasm/src/interpreter/executor.rs:1573–1591  ·  view source on GitHub ↗
(&mut self, time_budget: core::time::Duration)

Source from the content-addressed store, hash-verified

1571 #[cfg(feature = "std")]
1572 #[inline(always)]
1573 pub(crate) fn run_with_time_budget(&mut self, time_budget: core::time::Duration) -> Result<ExecState, Trap> {
1574 use crate::std::time::Instant;
1575 let start = Instant::now();
1576 if time_budget.is_zero() {
1577 return Ok(ExecState::Suspended(self.cf));
1578 }
1579
1580 loop {
1581 for _ in 0..128 {
1582 if self.exec()?.is_some() {
1583 return Ok(ExecState::Completed);
1584 }
1585 }
1586
1587 if start.elapsed() >= time_budget {
1588 return Ok(ExecState::Suspended(self.cf));
1589 }
1590 }
1591 }
1592}
1593
1594impl<'store> Executor<'store, true> {

Callers 1

exec_with_time_budgetMethod · 0.80

Calls 1

execMethod · 0.45

Tested by

no test coverage detected