1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::imports::*;

#[async_trait]
pub trait Service: Sync + Send {
    fn name(&self) -> &'static str {
        std::any::type_name::<Self>()
    }

    /// Start the service
    async fn spawn(self: Arc<Self>, runtime: Runtime) -> Result<()>;

    /// Signal the service termination (post a shutdown request)
    fn terminate(self: Arc<Self>);

    /// Block until the service is terminated
    async fn join(self: Arc<Self>) -> Result<()>;
}