A simple generic pool that supports both sync and async.
This crate provides a simple generic pool that uses channels instead of locks and supports both sync and async without dependence on any runtime.
toml
default = []
The features below are related to logging errors, which should be unreachable.
log
: Enables logging using the log
crate.tracing
: Enables logging using the tracing
crate.Non-async example:
```rust use piscina::Pool;
let mut pool = Pool::new(); pool.put(1); pool.put(2);
let item1 = pool.tryget(); assert!(item1.issome());
let item2 = pool.blocking_get();
let none = pool.tryget(); assert!(none.isnone());
drop(item1); let item3 = pool.tryget(); assert!(item3.issome()); ```
Async example:
```rust use piscina::Pool;
futures::executor::block_on(async { let mut pool = Pool::new(); pool.put(1); pool.put(2);
let item1 = pool.get().await;
let item2 = pool.get().await;
let none = pool.try_get();
assert!(none.is_none());
drop(item1);
let item3 = pool.get().await;
}); ```
Instead of using an Option
, this crate uses unsafe code ManuallyDrop
in PooledItem
.
And the only use of unsafe code ManuallyDrop::take()
occurs when PooledItem
is dropped.
pop()
and try_pop()
once an item becomes availableLicense: MIT/Apache-2.0