Skip to main content

cordis/
service.rs

1use std::future::Future;
2use std::pin::Pin;
3use std::sync::Arc;
4
5use thiserror::Error;
6
7use crate::context::Context;
8use crate::effect::Disposable;
9
10#[derive(Debug, Error)]
11pub enum CordisError {
12    #[error("configuration error: {0}")]
13    Configuration(String),
14    #[error("fiber error: {0}")]
15    Fiber(String),
16}
17
18pub type ServiceInitFuture<'a> =
19    Pin<Box<dyn Future<Output = Result<Option<Box<dyn Disposable>>, CordisError>> + Send + 'a>>;
20
21pub trait Service: Send + Sync + 'static {
22    fn name(&self) -> &'static str {
23        std::any::type_name::<Self>()
24    }
25
26    fn init(&self, _ctx: &Arc<Context>) -> ServiceInitFuture<'_> {
27        Box::pin(async move { Ok(None) })
28    }
29
30    fn check(&self) -> bool {
31        true
32    }
33}