use crate::application::lifecycle::termination_signal;
use crate::application::ty::Application;
use crate::application::{EngineError, Result};
impl<S> Application<S>
where
S: Clone + Send + Sync + 'static,
{
pub async fn run_with_health<F>(self, state_fn: F) -> Result<()>
where
F: Fn(&crate::application::Resources, &crate::application::Lifecycle) -> S
+ Send
+ Sync
+ 'static,
{
let bind_addr = format!("{}:{}", self.bind_address, self.port);
let listener = tokio::net::TcpListener::bind(&bind_addr)
.await
.map_err(|source| EngineError::BindListener {
address: bind_addr.clone(),
source,
})?;
self.serve_with_health(listener, state_fn, termination_signal())
.await
}
}