Module taskpool

Module taskpool 

Source
Expand description

§Task Pool Module

Provides a concurrent task execution pool with semaphore-based concurrency control and cancellation support. The TaskPool allows limiting the number of concurrent tasks while providing graceful shutdown capabilities.

§Features

  • Concurrency Control - Limits the number of simultaneously executing tasks
  • Cancellation Support - Can cancel all running tasks gracefully
  • Resource Management - Automatic cleanup and resource disposal
  • Clone Support - Multiple references to the same task pool

§Usage

use quetty_server::taskpool::TaskPool;

async fn example() {
    let pool = TaskPool::new(10); // Allow up to 10 concurrent tasks

    // Execute multiple tasks
    for i in 0..20 {
        pool.execute(async move {
            println!("Task {} executing", i);
            // Simulate work
            tokio::time::sleep(std::time::Duration::from_millis(100)).await;
        });
    }

    // Later, cancel all tasks if needed
    pool.cancel_all();
}

Structs§

TaskPool
A concurrent task execution pool with semaphore-based concurrency control.