1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use futures_util::future::BoxFuture;
use intertrait::CastFromSync;
use std::sync::Arc;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum AsyncServiceError {
    #[error("{0}")]
    Service(String),
}

pub type AsyncServiceResult<T> = std::result::Result<T, AsyncServiceError>;

pub type AsyncServiceFuture = BoxFuture<'static, AsyncServiceResult<()>>;

pub trait AsyncService: CastFromSync {
    fn ident(self: Arc<Self>) -> &'static str;
    fn start(self: Arc<Self>) -> AsyncServiceFuture;
    fn signal_exit(self: Arc<Self>);
    fn stop(self: Arc<Self>) -> AsyncServiceFuture;
}