use std::sync::Arc;
use tokio::sync::{OwnedSemaphorePermit, Semaphore};
#[derive(Clone)]
pub struct HeldConnection {
_permit: Arc<OwnedSemaphorePermit>,
}
impl HeldConnection {
pub(super) fn try_reserve(places: &Arc<Semaphore>) -> Option<Self> {
places.clone().try_acquire_owned().ok().map(|permit| Self {
_permit: Arc::new(permit),
})
}
}
impl std::fmt::Debug for HeldConnection {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("HeldConnection")
.finish_non_exhaustive()
}
}