async fn stop(&mut self, force: Option<broadcast::Receiver<()>>) -> Result<()> {
        let srv_handle = self.srv_handle.take().unwrap();
        let join_handle = srv_handle.stop(true);

        if let Some(mut force) = force {
            let h = Box::pin(join_handle);
            let f = Box::pin(force.recv());

            match futures::future::select(f, h).await {
                Either::Left((_x, _h)) => {
                    tracing::info!("{}: received force shutdown signal", self.name);
                    let task_handle = self.join_handle.as_ref().unwrap();
                    task_handle.abort();
                }
                Either::Right((_, _)) => {
                    tracing::info!("Done: {}: graceful shutdown", self.name);
                }
            }
        } else {
            tracing::info!(
                "{}: force is None, wait for join handle for ever",
                self.name
            );

            let res = join_handle.await;

            tracing::info!(
                "Done: {}: waiting for join handle for ever, res: {:?}",
                self.name,
                res
            );
        }
        Ok(())
    }
/// Blocking stop. It should not return until everything is cleaned up.
///
/// In case a graceful `stop()` had blocked for too long,
/// the caller submit a FORCE stop by sending a `()` to `force`.
/// An impl should either close everything at once, or just ignore the
/// `force` signal if it does not support force stop.
///
/// Calling `stop()` twice should get an error.
Blocking stop. It should not return until everything is cleaned up.

Calling `stop()` twice should get an error.
Blocking stop . It should not return until everything is cleaned up . Calling ` stop () ` twice should get an error .
async fn stop(&mut self, force: Option<broadcast::Receiver<()>>) -> Result<()> {
        let srv_handle = self.srv_handle.take().unwrap();
        let join_handle = srv_handle.stop(true);
        if let Some(mut force) = force {
            let h = Box::pin(join_handle);
            let f = Box::pin(force.recv());
            match futures::future::select(f, h).await {
                Either::Left((_x, _h)) => {
                    tracing::info!("{}: received force shutdown signal", self.name);
                    let task_handle = self.join_handle.as_ref().unwrap();
                    task_handle.abort();
                }
                Either::Right((_, _)) => {
                    tracing::info!("Done: {}: graceful shutdown", self.name);
                }
            }
        } else {
            tracing::info!(
                "{}: force is None, wait for join handle for ever",
                self.name
            );
            let res = join_handle.await;
            tracing::info!(
                "Done: {}: waiting for join handle for ever, res: {:?}",
                self.name,
                res
            );
        }
        Ok(())
    }
async fn stop ( & mut self , force : Option < broadcast :: Receiver < ( ) > > ) -> Result < ( ) > { let srv_handle = self . srv_handle . take ( ) . unwrap ( ) ; let join_handle = srv_handle . stop ( true ) ; if let Some ( mut force ) = force { let h = Box :: pin ( join_handle ) ; let f = Box :: pin ( force . recv ( ) ) ; match futures :: future :: select ( f , h ) . await { Either :: Left ( ( _x , _h ) ) => { tracing :: info ! ( " " self name ) ; let task_handle = self . join_handle . as_ref ( ) . unwrap ( ) ; task_handle . abort ( ) ; } Either :: Right ( ( _ , _ ) ) => { tracing :: info ! ( " " self name ) ; } } } else { tracing :: info ! ( " " self name ) ; let res = join_handle . await ; tracing :: info ! ( " " self name res ) ; } Ok ( ( ) ) }
Blocking stop.
Blocking stop .
&mut self
force
Option<broadcast::Receiver<()>>
&mut self
force
Option<broadcast::Receiver<()>>