-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Austin Bonander <austin@launchbadge.com>
- Loading branch information
Showing
11 changed files
with
1,278 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script scans the project for `mod.rs` files and exits with a nonzero code if it finds any. | ||
# | ||
# You can also call it with `--fix` to replace any `mod.rs` files with their 2018 edition equivalents. | ||
# The new files will be staged for commit for convenience. | ||
|
||
FILES=$(find ./ -name mod.rs -print) | ||
|
||
if [[ -z $FILES ]]; then | ||
exit 0 | ||
fi | ||
|
||
if [ "$1" != "--fix" ]; then | ||
echo 'This project uses the Rust 2018 module style. mod.rs files are forbidden.' | ||
echo "Execute \`$0 --fix\` to replace these with their 2018 equivalents and stage for commit." | ||
echo 'Found mod.rs files:' | ||
echo "$FILES" | ||
exit 1 | ||
fi | ||
|
||
echo 'Fixing Rust 2018 Module Style' | ||
|
||
while read -r file; do | ||
dest="$(dirname $file).rs" | ||
echo "$file -> $dest" | ||
mv $file $dest | ||
git add $dest | ||
done <<< $FILES | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use crate::pool::connection::{Idle, Pooled}; | ||
use crate::pool::options::PoolOptions; | ||
use crate::pool::shared::{SharedPool, TryAcquireResult}; | ||
use crate::pool::wait_list::WaitList; | ||
use crate::{Connect, Connection, DefaultRuntime, Runtime}; | ||
use crossbeam_queue::ArrayQueue; | ||
use std::sync::atomic::AtomicU32; | ||
use std::sync::Arc; | ||
use std::time::Instant; | ||
|
||
mod connection; | ||
mod options; | ||
mod shared; | ||
mod wait_list; | ||
|
||
pub struct Pool<Rt: Runtime, C: Connection<Rt>> { | ||
shared: Arc<SharedPool<Rt, C>>, | ||
} | ||
|
||
impl<Rt: Runtime, C: Connection<Rt>> Pool<Rt, C> { | ||
pub fn new(uri: &str) -> crate::Result<Self> { | ||
Self::builder().build(uri) | ||
} | ||
|
||
pub fn new_with(connect_options: <C as Connect<Rt>>::Options) -> Self { | ||
Self::builder().build_with(connect_options) | ||
} | ||
|
||
pub fn builder() -> PoolOptions<Rt, C> { | ||
PoolOptions::new() | ||
} | ||
} | ||
|
||
#[cfg(feature = "async")] | ||
impl<Rt: crate::Async, C: Connection<Rt>> Pool<Rt, C> { | ||
pub async fn connect(uri: &str) -> crate::Result<Self> { | ||
Self::builder().connect(uri).await | ||
} | ||
|
||
pub async fn connect_with(connect_options: <C as Connect<Rt>>::Options) -> crate::Result<Self> { | ||
Self::builder().connect_with(connect_options).await | ||
} | ||
|
||
pub async fn acquire(&self) -> crate::Result<Pooled<Rt, C>> {} | ||
|
||
async fn acquire_inner(&self, deadline: Option<Instant>) -> crate::Result<Pooled<Rt, C>> { | ||
let mut acquire_permit = None; | ||
|
||
loop { | ||
match self.shared.try_acquire(acquire_permit.take()) { | ||
TryAcquireResult::Acquired(mut conn) => { | ||
match self.shared.on_acquire_async(&mut conn) { | ||
Ok(()) => return Ok(conn.attach(&self.shared)), | ||
Err(e) => { | ||
log::info!("error from before_acquire: {:?}", e); | ||
} | ||
} | ||
} | ||
TryAcquireResult::Connect(permit) => self.shared.connect_async(permit).await, | ||
TryAcquireResult::Wait => {} | ||
TryAcquireResult::PoolClosed => Err(todo!("crate::Error::PoolClosed")), | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.