bikeshedder / deadpool

Dead simple pool implementation for rust with async-await
Apache License 2.0
1.08k stars 137 forks source link

Add new configuration: minimum count of elements. #352

Closed xuxiaocheng0201 closed 2 months ago

xuxiaocheng0201 commented 2 months ago

In my particular example, I need to retain at least one element in the pool. Is there any way to achieve this?

bikeshedder commented 2 months ago

What are you trying to do? Are you calling deadpool::managed::Pool::retain and just want one element to exist afterwards?

The simplest way I can think of would be this:

let item = pool.get().await;
pool.retain(|_, _| false);

This would cause one object to be grabbed from the pool. Then retain removes all other elements and afterwards that element is returned back to the pool.

This might actually be related to:

xuxiaocheng0201 commented 2 months ago

Thanks for your quick reply.

Actually the retain isn't what I want. I want at least one element which has the same lifetime with the pool. A tuple containing a element and the pool is possible. But this is not perfect because the extra element cannot be used.

xuxiaocheng0201 commented 2 months ago

This is duplicate with #245. I will subscribe that issus.