use std::future::IntoFuture;
use std::time::Duration;
use super::output::Output;
use crate::client::Client;
use crate::future::BoxedFuture;
#[must_use = "Does nothing unless you await!"]
pub struct TryConnect<'client> {
client: &'client Client,
timeout: Duration,
}
impl<'client> TryConnect<'client> {
#[inline]
pub(crate) fn new(client: &'client Client) -> Self {
Self {
client,
timeout: Duration::from_secs(60),
}
}
#[inline]
pub fn timeout(mut self, timeout: Duration) -> Self {
self.timeout = timeout;
self
}
}
impl<'client> IntoFuture for TryConnect<'client> {
type Output = Output<()>;
type IntoFuture = BoxedFuture<'client, Self::Output>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move { self.client.pool().try_connect(self.timeout).await })
}
}