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
2,972 downloads per month
Used in 5 crates
(4 directly)
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