Skip to main content

run_pool

Function run_pool 

Source
pub async fn run_pool<'a, G: PowGenerator + ?Sized>(
    generator: &'a G,
    label: &'a str,
    iteration_cap: Option<usize>,
    pow_min: Pow,
    data_hash: Hash,
) -> Result<(Salt, Pow, Hash)>
Expand description

Work-stealing dispatcher shared by both generate and generate_best_effort.

Algorithm:

  1. Register the job in the tracker (RAII so panic / cancel still cleans up).
  2. Initial fill: push one chunk onto each of pool_size() slots, clamped by iteration_cap when bounded.
  3. As each chunk completes, merge its best result. If pow_min is met, return immediately — the FuturesUnordered is dropped, discarding any in-flight chunks (the underlying worker / blocking thread continues silently and its result is lost).
  4. Otherwise, update the tracker / progress estimator, cooperatively yield, and refeed only the slot that just freed up. Fast slots end up processing more chunks than slow ones — no idle waiting on the slowest core.