Skip to main content

batch_decision

Function batch_decision 

Source
pub fn batch_decision(
    policy: &BatchPolicy,
    budget: NonZeroUsize,
    query: &BatchQuery,
) -> Result<BatchDecision, ExecError>
Expand description

Decide the route for one batch on budget threads under policy.

Forced strategies are clamped (lanes <= min(items, budget), lanes * item_threads <= budget) but never fall back. BatchStrategy::WholeBatchVendor returns ExecError::StrategyUnavailable when query.vendor_batch is false, before any output write. Auto narrows the budget first (see the module docs) and uses the original budget only for the forced strategies.

This function itself only refuses WholeBatchVendor. Whether a route can run the returned decision is the route’s own preflight: a decision with both lanes and item threads is honoured or refused before any output write, never partially applied (see BatchDecision’s route contract).

§Errors

ExecError::StrategyUnavailable for a forced WholeBatchVendor on a route without a vendor batch call.

§Examples

use std::num::NonZeroUsize;
use tcontract_exec::batch::{batch_decision, BatchPolicy, BatchQuery, BatchStrategy};

let budget = NonZeroUsize::new(4).unwrap();
let query = BatchQuery::new(2, 1024.0);
let split = BatchPolicy::new(BatchStrategy::Split {
    lanes: NonZeroUsize::new(8).unwrap(),
});
let d = batch_decision(&split, budget, &query).unwrap();
// Clamped to the items and the budget.
assert_eq!((d.lanes, d.item_threads), (2, 2));