pub fn stop_server() {
    log::info!("stopping server");
    let state = server_state.compare_and_swap(ServerState::Running, ServerState::Stopping);
    if state != ServerState::Running {
        return;
    }
    // borrow the server to stop the subsystems, drop it before the borrow_mut()
    let borrow = server.borrow();
    if let ServerField::Executor(executor) = &borrow.executor {
        executor.stop();
        // give the executor some time to stop threads.
        thread::sleep(Duration::from_millis(20));
    }
    if let ServerField::Scheduler(scheduler) = &borrow.scheduler {
        scheduler.stop()
    }
    if let ServerField::Monitor(monitor) = &borrow.monitor {
        monitor.stop()
    }
    drop(borrow);

    let mut s = server.borrow_mut();
    s.scheduler = ServerField::Uninitialized;
    s.executor = ServerField::Uninitialized;
    s.monitor = ServerField::Uninitialized;

    server_state.store(ServerState::Stopped);
    log::info!("server is now stopped");
}
/// The stop_server function stops the server, releasing all resources.
The stop_server function stops the server, releasing all resources.
The stop_server function stops the server releasing all resources .
pub fn stop_server() {
    log::info!("stopping server");
    let state = server_state.compare_and_swap(ServerState::Running, ServerState::Stopping);
    if state != ServerState::Running {
        return;
    }
    // borrow the server to stop the subsystems, drop it before the borrow_mut()
    let borrow = server.borrow();
    if let ServerField::Executor(executor) = &borrow.executor {
        executor.stop();
        // give the executor some time to stop threads.
        thread::sleep(Duration::from_millis(20));
    }
    if let ServerField::Scheduler(scheduler) = &borrow.scheduler {
        scheduler.stop()
    }
    if let ServerField::Monitor(monitor) = &borrow.monitor {
        monitor.stop()
    }
    drop(borrow);
    let mut s = server.borrow_mut();
    s.scheduler = ServerField::Uninitialized;
    s.executor = ServerField::Uninitialized;
    s.monitor = ServerField::Uninitialized;
    server_state.store(ServerState::Stopped);
    log::info!("server is now stopped");
}
pub fn stop_server ( ) { log :: info ! ( " " ) ; let state = server_state . compare_and_swap ( ServerState :: Running , ServerState :: Stopping ) ; if state != ServerState :: Running { return ; } // borrow the server to stop the subsystems, drop it before the borrow_mut() let borrow = server . borrow ( ) ; if let ServerField :: Executor ( executor ) = & borrow . executor { executor . stop ( ) ; // give the executor some time to stop threads. thread :: sleep ( Duration :: from_millis ( 20 ) ) ; } if let ServerField :: Scheduler ( scheduler ) = & borrow . scheduler { scheduler . stop ( ) } if let ServerField :: Monitor ( monitor ) = & borrow . monitor { monitor . stop ( ) } drop ( borrow ) ; let mut s = server . borrow_mut ( ) ; s . scheduler = ServerField :: Uninitialized ; s . executor = ServerField :: Uninitialized ; s . monitor = ServerField :: Uninitialized ; server_state . store ( ServerState :: Stopped ) ; log :: info ! ( " " ) ; }
The stop_server function stops the server, releasing all resources.
The stop_server function stops the server releasing all resources .