1 unstable release

0.1.0 Aug 20, 2023

#2024 in Asynchronous

Download history 1/week @ 2024-08-24 1/week @ 2024-08-31 8/week @ 2024-09-21 5/week @ 2024-09-28 3/week @ 2024-10-05 4/week @ 2024-10-12 21/week @ 2024-10-19 134/week @ 2024-10-26 30/week @ 2024-11-02

189 downloads per month

MIT license

13KB
126 lines

bounded_join_set

A Concurrency-Limited JoinSet for Tokio.

![MIT licensed][mit-badge] ![Build Status][actions-badge]

The bounded_join_set crate provides a simple wrapper around Tokio's JoinSet with a configurable concurrency limit. It exposes the same API as the native JoinSet, but ensures that no matter how many tasks you add to the set, only a predetermined number (based on the concurrency limit) will be polled concurrently.

Why use bounded_join_set?

In scenarios where you want to spawn multiple concurrent tasks using Tokio, but want to avoid overwhelming the system with too many simultaneous tasks, bounded_join_set comes to the rescue. It ensures that you won't exhaust system resources, while still benefiting from concurrency.

How to use

Add bounded_join_set to your Cargo.toml dependencies:

[dependencies]
bounded_join_set = "0.1.0"

Here's a basic usage example:

use bounded_join_set::JoinSet;

#[tokio::main]
async fn main() {
    let concurrency_limit = 5;
    let mut join_set = JoinSet::new(concurrency_limit);

    for _ in 0..10 {
        join_set.spawn(async {
            // Your concurrent task here.
        });
    }

    while join_set.join_next().await.is_some() {}
}

Features & Benefits

  • Simple API: If you're familiar with Tokio's JoinSet, you already know how to use bounded_join_set.
  • Resource Management: Prevents system overloads by controlling the number of concurrently polled tasks.
  • Flexible: Set your own concurrency limit according to your system's capabilities and requirements.

Limitations

While bounded_join_set aims to offer an enhanced concurrency control over Tokio's native JoinSet, there are certain limitations to be aware of:

  • No spawn_blocking Support: As of the current version, the crate does not support the spawn_blocking method provided by Tokio. If your application relies heavily on CPU-bound operations that would benefit from the spawn_blocking feature, you'll need to manage that separately from this crate. We are looking into extending support for this in future releases, but there's no definite timeline yet.

We're always keen on improving and expanding the capabilities of bounded_join_set. If you encounter any issues or have suggestions, please feel free to open an issue on our GitHub repository.

Contribution & Support

Contributions, feature requests, and feedback are always welcome. Feel free to open an issue or a pull request on the GitHub repository.

License: MIT

Dependencies

~2–7.5MB
~47K SLoC