Module
tuck/limits
src/tuck/limits.pookaPut expensive rendering in its own room. Budgets cover source size, final output size, BEAM work, worker heap, and elapsed time. Cancellation joins the worker before returning, so a timed-out filter cannot keep running.
API reference
class Budget(
max_source_bytes: Int,
max_output_bytes: Int,
max_reductions: Int,
max_heap_words: Int,
timeout_ms: Int
)
Byte limits describe UTF-8. Heap limits use BEAM words. Work is measured in reductions, so deeply nested templates do not need a guessed nesting cost.
max_source_bytes: Int
Intmax_output_bytes: Int
Intmax_reductions: Int
Intmax_heap_words: Int
Inttimeout_ms: Int
Int
fn(Int, Int, Int, Int, Int) -> tuck/limits.Budgetdefaults() -> Budget
fn() -> tuck/limits.BudgetOne MiB of source, four MiB of output, twenty million reductions, four million heap words, and five seconds.
assert limits.defaults().max_source_bytes == 1048576
run(source: String, budget: Budget, work: fn() -> a) -> Result(a, String)
fn(String, tuck/limits.Budget, fn() -> a) -> Result(a, String)Run a typed operation in a bounded worker. The callback's value is returned unchanged; only resource failures acquire an explanatory message.
output(value: String, budget: Budget) -> Result(String, String)
fn(String, tuck/limits.Budget) -> Result(String, String)Check the completed output inside its worker, before sending it to the caller. Interim allocations are covered by the worker's heap/work budgets.