Crates.io | apool |
lib.rs | apool |
version | 0.1.3 |
source | src |
created_at | 2021-08-21 19:50:28.125043 |
updated_at | 2021-08-22 00:39:11.975738 |
description | Async generic pool crate for rust |
homepage | https://github.com/post-rex/apool |
repository | https://github.com/post-rex/apool |
max_upload_size | |
id | 440431 |
size | 20,047 |
This crate allows you to create a Pool of any type T: Send + Sync
lazily.
When trying to acquire a &mut T
T
does not need to implement Clone, instead the Pool requites a type S
which acts as State, and a dyn Fn(&mut S, &mut PoolTransformer<T>)
which can create new instances of T
.
The Fn
will only be called if the maximum has not yet been reached.
let pool = Pool::<FakeDatabase, &'static str>::new(
4,
"fakedb://127.0.0.1:1337/fake_website",
|state, transformer| {
let url = *state;
transformer.spawn(async {
FakeDatabase::connect(url).await.unwrap()
});
},
);
let guard = pool.get().await;
guard.commit_data().await;