(&mut self, time_budget: core::time::Duration)
| 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 | |
| 1594 | impl<'store> Executor<'store, true> { |
no test coverage detected