MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / with_budget

Function with_budget

codegraph-kernel/src/parse_budget.rs:33–37  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
33pub 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

Calls 4

RestoreClass · 0.85
mapMethod · 0.80
withMethod · 0.80
fromFunction · 0.50