Crates.io | simple-pool |
lib.rs | simple-pool |
version | 0.0.18 |
source | src |
created_at | 2021-09-10 01:28:49.303582 |
updated_at | 2024-07-15 23:00:58.058298 |
description | Simple async pool for any kind of resources |
homepage | |
repository | https://github.com/alttch/simple-pool |
max_upload_size | |
id | 449075 |
size | 13,133 |
Simple and fast async pool for any kind of resources
This is a helper library to create custom pools of anything
https://crates.io/crates/simple-pool
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;
});
}
}