Skip to main content

Module concurrency

Module concurrency 

Source
Expand description

Concurrency abstraction layer for incremental analysis.

Provides unified interface for parallel execution across different deployment targets:

  • RayonExecutor: CPU-bound parallelism for CLI (multi-core)
  • TokioExecutor: Async I/O concurrency for all deployments
  • SequentialExecutor: Fallback for single-threaded execution

§Architecture

The concurrency layer adapts to deployment context via feature flags:

  • CLI with parallel feature: Rayon for CPU-bound work
  • All deployments: tokio for async I/O operations
  • Fallback: Sequential execution when parallelism unavailable

§Examples

§Basic Usage

use thread_flow::incremental::concurrency::{
    create_executor, ConcurrencyMode, ExecutionError,
};

// Create executor for current deployment
let executor = create_executor(ConcurrencyMode::Tokio { max_concurrent: 10 });

// Process batch of items
let items = vec![1, 2, 3, 4, 5];
let results = executor.execute_batch(items, |n| {
    // Your work here
    Ok(())
}).await?;

assert_eq!(results.len(), 5);

§Feature-Aware Execution

use thread_flow::incremental::concurrency::{
    create_executor, ConcurrencyMode,
};

// Automatically uses best executor for current build
#[cfg(feature = "parallel")]
let executor = create_executor(ConcurrencyMode::Rayon { num_threads: None });

#[cfg(not(feature = "parallel"))]
let executor = create_executor(ConcurrencyMode::Tokio { max_concurrent: 10 });

Structs§

RayonExecutor
CPU-bound parallel executor using Rayon thread pool.
SequentialExecutor
Sequential executor processing items one at a time.
TokioExecutor
Async I/O executor using tokio tasks with concurrency limit.

Enums§

ConcurrencyMode
Concurrency mode selection for executor factory.
ExecutionError
Errors that can occur during batch execution.
Executor
Unified executor enum combining all concurrency strategies.

Traits§

ConcurrencyExecutor
Unified interface for concurrent batch execution.

Functions§

create_executor
Create executor instance based on mode and available features.