Run `f` with a deadline `budget_ms` from now for every [`parse`] it makes; `None` (an older caller) leaves the parses unbounded, as before.
(budget_ms: Option<u32>, f: impl FnOnce() -> T)
| 31 | /// Run `f` with a deadline `budget_ms` from now for every [`parse`] it makes; |
| 32 | /// `None` (an older caller) leaves the parses unbounded, as before. |
| 33 | pub fn with_budget<T>(budget_ms: Option<u32>, f: impl FnOnce() -> T) -> T { |
| 34 | let deadline = budget_ms.map(|ms| (Instant::now() + Duration::from_millis(u64::from(ms)), ms)); |
| 35 | let _restore = Restore(DEADLINE.with(|d| d.replace(deadline))); |
| 36 | f() |
| 37 | } |
| 38 | |
| 39 | /// `parser.parse(source, None)`, cancelled once the extraction's deadline |
| 40 | /// passes: `Err("timeout: …")` then, and the old `Err("parser returned null |