Skip to main content

saddle_core/
lifecycle.rs

1use std::{future::Future, pin::Pin};
2
3use crate::Result;
4
5pub type LifecycleFuture<'a> = Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>;
6
7/// Object-safe lifecycle contract used by the Saddle application assembler.
8///
9/// Implementations must be safe to start once and shut down once. Ordering and
10/// graceful-drain policy belong to `saddle-runtime`, not this contract.
11pub trait ComponentLifecycle: Send + Sync {
12    fn name(&self) -> &'static str;
13
14    fn start(&self) -> LifecycleFuture<'_>;
15
16    fn shutdown(&self) -> LifecycleFuture<'_>;
17
18    /// The cleanup owner may correlate its original source with an existing
19    /// primary before recording. Components without their own source writer
20    /// retain the ordinary shutdown behavior.
21    fn shutdown_with_primary(
22        &self,
23        _primary: Option<crate::DiagnosticOccurrence>,
24    ) -> LifecycleFuture<'_> {
25        self.shutdown()
26    }
27}