#async-pool #resources #pool #async #tokio

simple-pool

Simple async pool for any kind of resources

16 releases

0.0.18 Jul 15, 2024
0.0.17 Mar 3, 2024
0.0.16 Dec 23, 2023
0.0.15 May 15, 2023
0.0.10 Sep 14, 2021

#1150 in Network programming

Download history 70/week @ 2024-07-27 30/week @ 2024-08-03 20/week @ 2024-08-10 13/week @ 2024-08-17 8/week @ 2024-08-24 2/week @ 2024-08-31 12/week @ 2024-09-07 23/week @ 2024-09-14 57/week @ 2024-09-21 1057/week @ 2024-09-28 986/week @ 2024-10-05 1221/week @ 2024-10-12 1152/week @ 2024-10-19 591/week @ 2024-10-26 406/week @ 2024-11-02 740/week @ 2024-11-09

2,972 downloads per month
Used in 5 crates (4 directly)

MIT license

12KB
269 lines

simple-pool

Simple and fast async pool for any kind of resources

The idea

This is a helper library to create custom pools of anything

Crate

https://crates.io/crates/simple-pool

Example

use simple_pool::ResourcePool;
use std::sync::Arc;
use tokio::net::TcpStream;

async fn test() {
    // create a local or static resource pool
    let resource_pool: Arc<ResourcePool<TcpStream>> =
        Arc::new(ResourcePool::new());
    {
        // put 20 tcp connections there
        for _ in 0..20 {
            let client = TcpStream::connect("127.0.0.1:80").await.unwrap();
            resource_pool.append(client);
        }
    }
    let n = 1_000_000;
    for _ in 0..n {
        let pool = resource_pool.clone();
        tokio::spawn(async move {
            // gets open tcp connection as soon as one is available
            let _client = pool.get().await;
        });
    }
}

Dependencies

~0.4–5MB
~11K SLoC