Skip to main content

take

Function take 

Source
pub fn take() -> bool
Expand description

Take a single permit from the ambient budget, if one is set.

Returns false if the budget has been exhausted.

This is the primitive every budgeted loop uses, the machine’s own included. The permit is taken out of the budget where it lives rather than out of a local copy of it, so anything which is called while a loop is running - a native function, or a nested execution of the machine - draws from the same budget and cannot escape it.

§Examples

use rune::runtime::budget;

budget::with(2, || {
    assert!(budget::take());
    assert!(budget::take());
    assert!(!budget::take());
})
.call();