Skip to main content

run_concurrent_streams

Function run_concurrent_streams 

Source
pub async fn run_concurrent_streams(
    estimated_total: u64,
    stream_count: usize,
    progress: Arc<Tracker>,
    label: &str,
    spawn_fn: impl FnMut(usize, Arc<LoopState>, u64) -> JoinHandle<Result<(), Error>>,
) -> Result<BandwidthResult, Error>
Expand description

Run a bandwidth test using multiple concurrent streams.

This is the shared spawn/collect/report pattern used by both download and upload tests. It:

  1. Creates a LoopState for the test
  2. Spawns stream_count tasks via spawn_fn
  3. Collects results, logging any task panics
  4. Returns a BandwidthResult (zeroed if all tasks failed)

The spawn_fn closure receives the stream index and a shared reference to the loop state. Each call should create and return a JoinHandle<()> that performs I/O and calls LoopState::record_bytes for each transferred chunk.

§Arguments

  • estimated_total — Estimated total bytes for progress bar initialization
  • stream_count — Number of concurrent streams to spawn
  • progress — Shared progress bar for the test phase
  • spawn_fn — Closure that creates one stream’s async task

§Panics

Individual task panics are caught and logged; they do not propagate.