pub async fn timeout_get(&self, timeouts: &Timeouts) -> Result<W, PoolError<M::Error>> {
        self.inner.available.fetch_sub(1, Ordering::Relaxed);

        let mut obj = Object {
            obj: None,
            state: ObjectState::Waiting,
            pool: Arc::downgrade(&self.inner),
        };

        let non_blocking = match timeouts.wait {
            Some(t) => t.as_nanos() == 0,
            None => false,
        };

        let permit = if non_blocking {
            self.inner.semaphore.try_acquire().map_err(|e| match e {
                TryAcquireError::Closed => PoolError::Closed,
                TryAcquireError::NoPermits => PoolError::Timeout(TimeoutType::Wait),
            })?
        } else {
            apply_timeout(
                &self.inner.config.runtime,
                TimeoutType::Wait,
                self.inner.config.timeouts.wait,
                async {
                    self.inner
                        .semaphore
                        .acquire()
                        .await
                        .map_err(|_| PoolError::Closed)
                },
            )
            .await?
        };

        permit.forget();

        loop {
            obj.state = ObjectState::Receiving;
            let inner_obj = {
                let mut queue = self.inner.queue.lock().unwrap();
                queue.pop()
            };
            match inner_obj {
                Some(inner_obj) => {
                    // Recycle existing object
                    obj.state = ObjectState::Recycling;
                    obj.obj = Some(inner_obj);
                    match apply_timeout(
                        &self.inner.config.runtime,
                        TimeoutType::Recycle,
                        self.inner.config.timeouts.recycle,
                        self.inner.manager.recycle(&mut obj),
                    )
                    .await
                    {
                        Ok(_) => break,
                        Err(_) => {
                            self.inner.available.fetch_sub(1, Ordering::Relaxed);
                            self.inner.size.fetch_sub(1, Ordering::Relaxed);
                            continue;
                        }
                    }
                }
                None => {
                    // Create new object
                    obj.state = ObjectState::Creating;
                    self.inner.available.fetch_add(1, Ordering::Relaxed);
                    self.inner.size.fetch_add(1, Ordering::Relaxed);
                    obj.obj = Some(
                        apply_timeout(
                            &self.inner.config.runtime,
                            TimeoutType::Create,
                            self.inner.config.timeouts.create,
                            self.inner.manager.create(),
                        )
                        .await?,
                    );
                    break;
                }
            }
        }

        obj.state = ObjectState::Ready;
        Ok(obj.into())
    }
/// Retrieve object using a different timeout config than the one
/// configured.
Retrieve object using a different timeout config than the one
configured.
Retrieve object using a different timeout config than the one configured .
pub async fn timeout_get(&self, timeouts: &Timeouts) -> Result<W, PoolError<M::Error>> {
        self.inner.available.fetch_sub(1, Ordering::Relaxed);
        let mut obj = Object {
            obj: None,
            state: ObjectState::Waiting,
            pool: Arc::downgrade(&self.inner),
        };
        let non_blocking = match timeouts.wait {
            Some(t) => t.as_nanos() == 0,
            None => false,
        };
        let permit = if non_blocking {
            self.inner.semaphore.try_acquire().map_err(|e| match e {
                TryAcquireError::Closed => PoolError::Closed,
                TryAcquireError::NoPermits => PoolError::Timeout(TimeoutType::Wait),
            })?
        } else {
            apply_timeout(
                &self.inner.config.runtime,
                TimeoutType::Wait,
                self.inner.config.timeouts.wait,
                async {
                    self.inner
                        .semaphore
                        .acquire()
                        .await
                        .map_err(|_| PoolError::Closed)
                },
            )
            .await?
        };
        permit.forget();
        loop {
            obj.state = ObjectState::Receiving;
            let inner_obj = {
                let mut queue = self.inner.queue.lock().unwrap();
                queue.pop()
            };
            match inner_obj {
                Some(inner_obj) => {
                    // Recycle existing object
                    obj.state = ObjectState::Recycling;
                    obj.obj = Some(inner_obj);
                    match apply_timeout(
                        &self.inner.config.runtime,
                        TimeoutType::Recycle,
                        self.inner.config.timeouts.recycle,
                        self.inner.manager.recycle(&mut obj),
                    )
                    .await
                    {
                        Ok(_) => break,
                        Err(_) => {
                            self.inner.available.fetch_sub(1, Ordering::Relaxed);
                            self.inner.size.fetch_sub(1, Ordering::Relaxed);
                            continue;
                        }
                    }
                }
                None => {
                    // Create new object
                    obj.state = ObjectState::Creating;
                    self.inner.available.fetch_add(1, Ordering::Relaxed);
                    self.inner.size.fetch_add(1, Ordering::Relaxed);
                    obj.obj = Some(
                        apply_timeout(
                            &self.inner.config.runtime,
                            TimeoutType::Create,
                            self.inner.config.timeouts.create,
                            self.inner.manager.create(),
                        )
                        .await?,
                    );
                    break;
                }
            }
        }
        obj.state = ObjectState::Ready;
        Ok(obj.into())
    }
pub async fn timeout_get ( & self , timeouts : & Timeouts ) -> Result < W , PoolError < M :: Error > > { self . inner . available . fetch_sub ( 1 , Ordering :: Relaxed ) ; let mut obj = Object { obj : None , state : ObjectState :: Waiting , pool : Arc :: downgrade ( & self . inner ) , } ; let non_blocking = match timeouts . wait { Some ( t ) => t . as_nanos ( ) == 0 , None => false , } ; let permit = if non_blocking { self . inner . semaphore . try_acquire ( ) . map_err ( | e | match e { TryAcquireError :: Closed => PoolError :: Closed , TryAcquireError :: NoPermits => PoolError :: Timeout ( TimeoutType :: Wait ) , } ) ? } else { apply_timeout ( & self . inner . config . runtime , TimeoutType :: Wait , self . inner . config . timeouts . wait , async { self . inner . semaphore . acquire ( ) . await . map_err ( | _ | PoolError :: Closed ) } , ) . await ? } ; permit . forget ( ) ; loop { obj . state = ObjectState :: Receiving ; let inner_obj = { let mut queue = self . inner . queue . lock ( ) . unwrap ( ) ; queue . pop ( ) } ; match inner_obj { Some ( inner_obj ) => { // Recycle existing object obj . state = ObjectState :: Recycling ; obj . obj = Some ( inner_obj ) ; match apply_timeout ( & self . inner . config . runtime , TimeoutType :: Recycle , self . inner . config . timeouts . recycle , self . inner . manager . recycle ( & mut obj ) , ) . await { Ok ( _ ) => break , Err ( _ ) => { self . inner . available . fetch_sub ( 1 , Ordering :: Relaxed ) ; self . inner . size . fetch_sub ( 1 , Ordering :: Relaxed ) ; continue ; } } } None => { // Create new object obj . state = ObjectState :: Creating ; self . inner . available . fetch_add ( 1 , Ordering :: Relaxed ) ; self . inner . size . fetch_add ( 1 , Ordering :: Relaxed ) ; obj . obj = Some ( apply_timeout ( & self . inner . config . runtime , TimeoutType :: Create , self . inner . config . timeouts . create , self . inner . manager . create ( ) , ) . await ? , ) ; break ; } } } obj . state = ObjectState :: Ready ; Ok ( obj . into ( ) ) }
Retrieve object using a different timeout config than the one
configured.
Retrieve object using a different timeout config than the one configured .
&self
timeouts
&Timeouts
&self
timeouts
&Timeouts