pub struct AsterRuntime<S> { /* private fields */ }Expand description
Product-facing runtime runner built from service and component registrations.
Product entrypoints should register the main service as a component, then register database, task, mail, product, or shutdown bundles in the same chain:
AsterRuntime::builder()
.component(http_component(...))
.component(database_component(...))
.component(task_component(...))
.run()
.await?;Implementations§
Source§impl AsterRuntime<()>
impl AsterRuntime<()>
Sourcepub fn builder() -> AsterRuntimeBuilder<()>
pub fn builder() -> AsterRuntimeBuilder<()>
Creates a runtime builder.
Source§impl<S> AsterRuntime<S>where
S: Future,
impl<S> AsterRuntime<S>where
S: Future,
Sourcepub async fn run(self) -> Result<S::Output, AsterRuntimeError>
pub async fn run(self) -> Result<S::Output, AsterRuntimeError>
Runs startup, the main service, before-shutdown hooks, and component shutdown. The owned signal listener is cancelled and joined after the service stops, before cleanup.
When a required startup phase aborts, component shutdown phases still run best-effort before the startup error is returned, so components that already completed startup (connection pools, spawned workers, buffered writers) get a chance to release their resources.
§Errors
Returns a startup report error when a required startup phase aborts, or a shutdown
report error after all cleanup phases run if any phase fails or times out. A panicking
before-shutdown hook also returns an error after component cleanup. Best-effort product
hooks should handle their own errors and return success explicitly.
Service panics become AsterRuntimeError::Service after cleanup, preserving secondary
hook and shutdown failures without exposing the panic payload. Ordinary service outputs
(including product Result::Err values) are returned unchanged when cleanup succeeds.
This also covers destruction of the service future after it finishes.
The shared and service cancellation tokens are cancelled before cleanup on every exit.
Dropping a polled run future also cancels these tokens, but cannot await cleanup; callers
must let run complete to guarantee asynchronous drain and worker joins.