use std::{future::Future, pin::Pin};
use crate::Result;
pub type LifecycleFuture<'a> = Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>;
/// Object-safe lifecycle contract used by the Saddle application assembler.
///
/// Implementations must be safe to start once and shut down once. Ordering and
/// graceful-drain policy belong to `saddle-runtime`, not this contract.
pub trait ComponentLifecycle: Send + Sync {
fn name(&self) -> &'static str;
fn start(&self) -> LifecycleFuture<'_>;
fn shutdown(&self) -> LifecycleFuture<'_>;
/// The cleanup owner may correlate its original source with an existing
/// primary before recording. Components without their own source writer
/// retain the ordinary shutdown behavior.
fn shutdown_with_primary(
&self,
_primary: Option<crate::DiagnosticOccurrence>,
) -> LifecycleFuture<'_> {
self.shutdown()
}
}