Expand description
A concurrent pool for lending and reusing items.
This crate provides a LendPool
type for managing reusable items in a concurrent or
asynchronous context. Items can be checked out (“loaned”) as Loan
guards and are
automatically returned to the pool when the guard is dropped.
§Crate Features
-
sync
Enables the synchronous blocking method [LendPool::loan_sync
], which will block the current thread until an item becomes available. -
async
Enables the asynchronous method [LendPool::loan_async
], which willawait
a notification until an item becomes available.
§Examples
use lendpool::LendPool;
// Create a new pool and add items
let pool = LendPool::new();
pool.add(1);
pool.add(2);
// Loan an item (non-blocking)
if let Some(loan) = pool.loan() {
println!("Got item: {}", *loan);
}; // The `Loan` is dropped here, returning items to the pool
Structs§
- Lend
Pool - A thread-safe or async-aware pool of reusable items.
- Loan
- A guard representing a borrowed item from a
LendPool
.