Skip to main content

Module lifespan

Module lifespan 

Source
Expand description

Application lifespan: startup/shutdown hooks and scoped resources.

Hooks run in registration order at startup and in reverse order at shutdown; hooks of mounted child apps run after the parent’s at startup and before them at shutdown. A failing startup hook aborts startup with ServerError::Lifespan after reverse-order cleanup. At shutdown every hook runs even if one fails; the first error is reported.

App::lifespan_resource is the equivalent of FastAPI’s lifespan context manager: a value created at startup, injected with Resource<T>, and cleaned up at shutdown.

Structs§

Lifespan
The startup and shutdown hooks collected from an app tree.
ManagedLifespan
Owns a running lifespan and its cancellation-safe cleanup supervisor.
Resource
Handler argument giving access to a value created by App::lifespan_resource. Responds 503 until startup has completed (and again after shutdown).

Constants§

DEFAULT_SHUTDOWN_BUDGET
Default budget for request draining and lifespan teardown.