serviceless/service.rs
1use async_trait::async_trait;
2
3use crate::{Address, Context};
4
5/// A service is an running like thread
6#[async_trait]
7pub trait Service: Send + Sized + 'static {
8 fn start(self) -> Address<Self> {
9 Context::new().run(self)
10 }
11
12 fn start_by_context(self, ctx: Context<Self>) -> Address<Self> {
13 ctx.run(self)
14 }
15
16 /// Hook for service started
17 async fn started(&mut self, _ctx: &mut Context<Self>) {}
18
19 /// Hook for service stopped
20 async fn stopped(&mut self, _ctx: &mut Context<Self>) {}
21}