Skip to main content

spawn_with_lifecycle

Function spawn_with_lifecycle 

Source
pub async fn spawn_with_lifecycle<F>(
    addr: &str,
    handler: F,
    config: LifecycleConfig,
) -> Result<HttpServer>
where F: Fn(HttpRequest) -> HttpResponse + Send + Sync + 'static,
Expand description

Bind addr, spawn the LIFECYCLE-AWARE accept loop, and return a handle that exposes the full production lifecycle: HttpServer::set_ready, HttpServer::drain, and — because config.stamp_correlation_id defaults on — an X-Correlation-Id on every response. THE entry an embedder (and the AOT Serve lowering, via a config seam) uses for a server that “stays serving”: graceful drain, readiness gating, bounded backpressure, per-request time bounds, malformed-flood survival, and correlation ids.

The server starts READY (accepting traffic the moment it is bound, the deployed default); an orchestrator that wants a warm-up window flips it with set_ready(false) up front and back on once dependencies are wired.

Always the tokio engine: the drain/readiness handle needs a task, not the io_uring engine’s OS threads (whose blocking serve entry has no handle to flip readiness on anyway — see the module docs).