servlet 1.2.0

A small application runtime with an explicit operational contract
Documentation
//! Embedded and process-oriented entry points share the same coordinator.

use crate::{Error, Result, Running, lifecycle, process};

use super::App;

impl App<()> {
    /// Start on the current Tokio executor without signals or global logging.
    ///
    /// Waits for deferred setup, each worker's readiness acknowledgment, and each
    /// registered check's first success before opening admission. A check can
    /// become unhealthy again while another startup gate is pending; inspect
    /// [`crate::AppHandle::is_ready`] for current cached readiness.
    ///
    /// Cancelling this future requests rollback in the background. Keep the
    /// executor alive for cleanup; only awaited completion confirms the outcome.
    pub async fn start(self) -> Result<Running> {
        self.initialize_unit_task_state();
        lifecycle::start(self.registration, self.router).await
    }

    /// Run setup and its readiness gates, then await normal managed cleanup.
    ///
    /// Intended for finite commands such as migrations. Commands do not bind
    /// listeners and must not register application routes, workers, or services.
    /// Like [`Self::start`], this uses the current runtime without process signals.
    pub async fn run_once(self) -> Result<()> {
        if self.registration.http || !self.registration.workers.is_empty() {
            return Err(Error::Registration(
                "a finite command cannot register routes, workers, or services".into(),
            ));
        }
        let running = self
            .configure(|config| config.admin_bind = None)
            .start()
            .await?;
        running.handle().shutdown();
        running.wait().await
    }

    /// Install process signal handling, start the application, and await completion.
    ///
    /// SIGTERM and interrupt request the same graceful shutdown as `AppHandle`.
    /// Cancelling this future requests shutdown. It never resizes an executor or
    /// installs a global logging subscriber.
    pub async fn run(self) -> Result<()> {
        self.initialize_unit_task_state();
        process::run_app(self.registration, self.router).await
    }

    fn initialize_unit_task_state(&self) {
        if let Some(task_state) = &self.task_state {
            task_state.get_or_init(|| ());
        }
    }
}