You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asyncband.apache.org by ti...@apache.org on 2026/08/23 19:31:15 UTC
(asyncband) 01/02: refactor(pool): align internal organization
This is an automated email from the ASF dual-hosted git repository.
tisonkun pushed a commit to branch codex/pool-followup-review
in repository https://gitbox.apache.org/repos/asf/asyncband.git
commit 3f50734ab759426d87ccc81d2a2e2f4ee63d3e64
Author: tison <wa...@gmail.com>
AuthorDate: Mon Aug 24 03:23:19 2026 +0800
refactor(pool): align internal organization
---
asyncband/src/pool/bounded.rs | 2 +-
asyncband/src/pool/common.rs | 2 +-
asyncband/src/pool/mod.rs | 12 ++++++------
asyncband/src/pool/state.rs | 31 ++++++++++++++-----------------
4 files changed, 22 insertions(+), 25 deletions(-)
diff --git a/asyncband/src/pool/bounded.rs b/asyncband/src/pool/bounded.rs
index 25ea11f..b6f96ad 100644
--- a/asyncband/src/pool/bounded.rs
+++ b/asyncband/src/pool/bounded.rs
@@ -191,7 +191,7 @@ impl<M: ManageObject> Pool<M> {
/// The pool reserves only capacity that is immediately available and never waits for
/// checked-out objects. Existing idle objects count toward the target, and the pool's
/// maximum size is never exceeded. Concurrent calls and checkouts can change the observed
- /// idle count while this method is running, so the target is best effort rather than a
+ /// idle count while this method is running, so the target is the best effort rather than a
/// postcondition.
///
/// Returns the number of objects created. If [`ManageObject::create`] fails, objects created by
diff --git a/asyncband/src/pool/common.rs b/asyncband/src/pool/common.rs
index d6f54f2..c12ef2e 100644
--- a/asyncband/src/pool/common.rs
+++ b/asyncband/src/pool/common.rs
@@ -105,7 +105,7 @@ pub trait ManageObject: Send + Sync {
fn on_detached(&self, _o: &mut Self::Object) {}
}
-/// Queue strategy when dequeuing objects from the object pool.
+/// Queue strategy when dequeue objects from the object pool.
#[derive(Debug, Default, Clone, Copy)]
pub enum QueueStrategy {
/// First in first out.
diff --git a/asyncband/src/pool/mod.rs b/asyncband/src/pool/mod.rs
index 46e5567..40a1deb 100644
--- a/asyncband/src/pool/mod.rs
+++ b/asyncband/src/pool/mod.rs
@@ -171,14 +171,14 @@
//! }
//! ```
-pub use common::ManageObject;
-pub use common::ObjectStatus;
-pub use common::QueueStrategy;
-pub use common::RecycleCancelledStrategy;
-pub use common::RetainResult;
-
mod common;
mod state;
pub mod bounded;
pub mod unbounded;
+
+pub use self::common::ManageObject;
+pub use self::common::ObjectStatus;
+pub use self::common::QueueStrategy;
+pub use self::common::RecycleCancelledStrategy;
+pub use self::common::RetainResult;
diff --git a/asyncband/src/pool/state.rs b/asyncband/src/pool/state.rs
index 1a57427..fc53614 100644
--- a/asyncband/src/pool/state.rs
+++ b/asyncband/src/pool/state.rs
@@ -22,13 +22,13 @@ use crate::pool::QueueStrategy;
use crate::pool::RetainResult;
#[derive(Debug)]
-pub(crate) struct ObjectState<T> {
- pub(crate) o: T,
- pub(crate) status: ObjectStatus,
+pub struct ObjectState<T> {
+ pub o: T,
+ pub status: ObjectStatus,
}
impl<T> ObjectState<T> {
- pub(crate) fn new(o: T) -> Self {
+ pub fn new(o: T) -> Self {
Self {
o,
status: ObjectStatus::default(),
@@ -37,48 +37,48 @@ impl<T> ObjectState<T> {
}
#[derive(Debug)]
-pub(crate) struct PoolState<T> {
+pub struct PoolState<T> {
idle: VecDeque<ObjectState<T>>,
current_size: usize,
}
impl<T> PoolState<T> {
- pub(crate) const fn new() -> Self {
+ pub const fn new() -> Self {
Self {
idle: VecDeque::new(),
current_size: 0,
}
}
- pub(crate) fn current_size(&self) -> usize {
+ pub fn current_size(&self) -> usize {
self.current_size
}
- pub(crate) fn idle_count(&self) -> usize {
+ pub fn idle_count(&self) -> usize {
self.idle.len()
}
- pub(crate) fn pop(&mut self, strategy: QueueStrategy) -> Option<ObjectState<T>> {
+ pub fn pop(&mut self, strategy: QueueStrategy) -> Option<ObjectState<T>> {
match strategy {
QueueStrategy::Fifo => self.idle.pop_front(),
QueueStrategy::Lifo => self.idle.pop_back(),
}
}
- pub(crate) fn add_idle(&mut self, state: ObjectState<T>) {
+ pub fn add_idle(&mut self, state: ObjectState<T>) {
self.current_size += 1;
self.idle.push_back(state);
}
- pub(crate) fn add_active(&mut self) {
+ pub fn add_active(&mut self) {
self.current_size += 1;
}
- pub(crate) fn return_idle(&mut self, state: ObjectState<T>) {
+ pub fn return_idle(&mut self, state: ObjectState<T>) {
self.idle.push_back(state);
}
- pub(crate) fn detach(&mut self) {
+ pub fn detach(&mut self) {
self.current_size = self
.current_size
.checked_sub(1)
@@ -86,10 +86,7 @@ impl<T> PoolState<T> {
}
/// Retains matching idle objects without losing any object if the predicate panics.
- pub(crate) fn retain(
- &mut self,
- mut f: impl FnMut(&mut T, ObjectStatus) -> bool,
- ) -> RetainResult<T> {
+ pub fn retain(&mut self, mut f: impl FnMut(&mut T, ObjectStatus) -> bool) -> RetainResult<T> {
let len = self.idle.len();
let mut retained = 0;
let mut current = 0;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@asyncband.apache.org
For additional commands, e-mail: commits-help@asyncband.apache.org