Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix configuration of queue strategy #165

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bb8/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub struct Builder<M: ManageConnection> {
}

/// bb8's queue strategy when getting pool resources
#[derive(Debug)]
#[derive(Debug, Clone, Copy)]
pub enum QueueStrategy {
/// First in first out
/// This strategy behaves like a queue
Expand Down
6 changes: 3 additions & 3 deletions bb8/src/internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ where
conns: VecDeque<IdleConn<M::Connection>>,
num_conns: u32,
pending_conns: u32,
queue_strategy: QueueStrategy,
}

impl<M> PoolInternals<M>
Expand All @@ -81,6 +80,8 @@ where
self.num_conns += 1;
}

let queue_strategy = pool.statics.queue_strategy;

let mut guard = InternalsGuard::new(conn, pool);
while let Some(waiter) = self.waiters.pop_front() {
// This connection is no longer idle, send it back out
Expand All @@ -95,7 +96,7 @@ where

// Queue it in the idle queue
let conn = IdleConn::from(guard.conn.take().unwrap());
match self.queue_strategy {
match queue_strategy {
QueueStrategy::Fifo => self.conns.push_back(conn),
QueueStrategy::Lifo => self.conns.push_front(conn),
}
Expand Down Expand Up @@ -180,7 +181,6 @@ where
conns: VecDeque::new(),
num_conns: 0,
pending_conns: 0,
queue_strategy: QueueStrategy::default(),
}
}
}
Expand Down