adirector 0.1.1

asynchronous tokio task spawner with a limited size
Documentation
  • Coverage
  • 83.33%
    5 out of 6 items documented4 out of 5 items with examples
  • Size
  • Source code size: 42.51 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.59 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • priv2024

adirector

License Cargo Documentation

asynchronous tokio task spawner with a limited size.

Full example:

use adirector::{Director, DirectorError};

#[tokio: main]
async fn main() -> Result<(), DirectorError> {
    // create executor that allow 10 tasks concurrently.
    let mut director = Director::new(10);

    // read line by line stdin
    let mut lines = BufReader::new(stdin()).lines();
    while let Some(line) = lines.next_line().await.unwrap() {
        director.spawn(async move {
            println!("{}", line);
            sleep(Duration::from_millis(50)).await;
        }).await?; // Suspends until the task is spawned
    }

    // Wait for remaining tasks to complete
    director.join_all().await
}

Implementation

A Semaphore is used to limit the count of tasks, and a JoinSet to join all tasks at once.

Dependencies

  • tokio with rt sync features