Serviceless is an simple actor model in rust, like actix but simple and async.
Currently, this crate only use tokio as backend.
This crate is no unsafe code.
This crate provide API same like actix
. But all api is async include handler.
Service
is a Actor
in Actor Model.
We can impl an Service
on an struct to delcare an Service
.
```rust pub struct Service0 {}
impl Service for Service0 {} ```
The Service
provide hook named started
and stopped
, them all are async.
Please use async_trait
macros.
```rust pub struct Service1 {}
impl Service for Service1 {
async fn started(&mut self, _ctx: &mut Context
Start a service is very simple, only create it can call start
method.
rust
let svc = Service1 {};
svc.start();
Note: this function must call in async function or after async runtime initialized. If not, it will panic.
When a service started, we can call stop and pause method on context
.
You can call these function in Service Hook or in Handler.
A service can sending an message to other service, or called by other service.
To call other Service, we must declare an Message
first.
Any type can be a message, only need impl Message trait on struct and define an result.
```rust pub struct Messagep {}
pub struct MessageResult {}
impl Message for Message0 { type Result = MessageResult; } ```
Impl Handler on service, we can make a service accept call from other service.
```rust
impl Handler
Handler also an async function, please use async_trait
macros.
When we start an service, we can get an address. We also can get it from Context.
The address can make call or send.
ServiceStopped
from Error.ServicePaused
from Error.ServiceStopped
from Error.