fn spawn_reaper<DB: Database>(pool: &Arc<SharedPool<DB>>) {
    let period = match (pool.options.max_lifetime, pool.options.idle_timeout) {
        (Some(it), None) | (None, Some(it)) => it,

        (Some(a), Some(b)) => cmp::min(a, b),

        (None, None) => return,
    };

    let pool = Arc::clone(&pool);

    spawn(async move {
        while !pool.is_closed.load(Ordering::Acquire) {
            // reap at most the current size minus the minimum idle
            let max_reaped = pool.size().saturating_sub(pool.options.min_connections);

            // collect connections to reap
            let (reap, keep) = (0..max_reaped)
                // only connections waiting in the queue
                .filter_map(|_| pool.pop_idle())
                .partition::<Vec<_>, _>(|conn| {
                    is_beyond_idle(conn, &pool.options) || is_beyond_lifetime(conn, &pool.options)
                });

            for conn in keep {
                // return these connections to the pool first
                pool.idle_conns
                    .push(conn.into_leakable())
                    .expect("BUG: connection queue overflow in spawn_reaper");
            }

            for conn in reap {
                let _ = conn.close().await;
            }

            sleep(period).await;
        }
    });
}
/// if `max_lifetime` or `idle_timeout` is set, spawn a task that reaps senescent connections
if `max_lifetime` or `idle_timeout` is set, spawn a task that reaps senescent connections
if ` max_lifetime ` or ` idle_timeout ` is set spawn a task that reaps senescent connections
fn spawn_reaper<DB: Database>(pool: &Arc<SharedPool<DB>>) {
    let period = match (pool.options.max_lifetime, pool.options.idle_timeout) {
        (Some(it), None) | (None, Some(it)) => it,
        (Some(a), Some(b)) => cmp::min(a, b),
        (None, None) => return,
    };
    let pool = Arc::clone(&pool);
    spawn(async move {
        while !pool.is_closed.load(Ordering::Acquire) {
            // reap at most the current size minus the minimum idle
            let max_reaped = pool.size().saturating_sub(pool.options.min_connections);
            // collect connections to reap
            let (reap, keep) = (0..max_reaped)
                // only connections waiting in the queue
                .filter_map(|_| pool.pop_idle())
                .partition::<Vec<_>, _>(|conn| {
                    is_beyond_idle(conn, &pool.options) || is_beyond_lifetime(conn, &pool.options)
                });
            for conn in keep {
                // return these connections to the pool first
                pool.idle_conns
                    .push(conn.into_leakable())
                    .expect("BUG: connection queue overflow in spawn_reaper");
            }
            for conn in reap {
                let _ = conn.close().await;
            }
            sleep(period).await;
        }
    });
}
fn spawn_reaper < DB : Database > ( pool : & Arc < SharedPool < DB > > ) { let period = match ( pool . options . max_lifetime , pool . options . idle_timeout ) { ( Some ( it ) , None ) | ( None , Some ( it ) ) => it , ( Some ( a ) , Some ( b ) ) => cmp :: min ( a , b ) , ( None , None ) => return , } ; let pool = Arc :: clone ( & pool ) ; spawn ( async move { while ! pool . is_closed . load ( Ordering :: Acquire ) { // reap at most the current size minus the minimum idle let max_reaped = pool . size ( ) . saturating_sub ( pool . options . min_connections ) ; // collect connections to reap let ( reap , keep ) = ( 0 .. max_reaped ) // only connections waiting in the queue . filter_map ( | _ | pool . pop_idle ( ) ) . partition :: < Vec < _ > , _ > ( | conn | { is_beyond_idle ( conn , & pool . options ) || is_beyond_lifetime ( conn , & pool . options ) } ) ; for conn in keep { // return these connections to the pool first pool . idle_conns . push ( conn . into_leakable ( ) ) . expect ( " " ) ; } for conn in reap { let _ = conn . close ( ) . await ; } sleep ( period ) . await ; } } ) ; }
if `max_lifetime` or `idle_timeout` is set, spawn a task that reaps senescent connections
if ` max_lifetime ` or ` idle_timeout ` is set spawn a task that reaps senescent connections
pool
&Arc<SharedPool<DB>>
pool
&Arc<SharedPool<DB>>