I have found these related issues/pull requests
None found
Description
There isn't an easy way to do a graceful shutdown in a pool may be cloned. E.g. the below may not work as intended:
let p: Pool = make_pool();
let p1 = p.clone();
// May fail if `p` is closed before `p1` is used
thread::spawn(|| do_something(p1));
p.close().await;
If you want both of these features then currently the only option is to separately track how many Pool handles exist. This is redundant though, since Pool already has this information internally.
Prefered solution
Add a way to close the pool only if it is the last one left:
impl Pool {
/// Close this pool if there are no other clones. Returns `true` if the pool was closed.
pub async fn close_if_unique(self) -> bool {
match Arc::into_inner(self.0) {
Some(inner) => {
inner.close().await;
true
}
None => false
}
}
}
Alternatively or additionally, give access to the count:
impl Pool {
pub fn handle_count(&self) -> usize {
Arc::strong_count(&self.0)
}
}
Is this a breaking change? Why or why not?
Not a breaking change, API addition.
I have found these related issues/pull requests
None found
Description
There isn't an easy way to do a graceful shutdown in a pool may be cloned. E.g. the below may not work as intended:
If you want both of these features then currently the only option is to separately track how many
Poolhandles exist. This is redundant though, sincePoolalready has this information internally.Prefered solution
Add a way to close the pool only if it is the last one left:
Alternatively or additionally, give access to the count:
Is this a breaking change? Why or why not?
Not a breaking change, API addition.