Serviceless
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.
Usage
This crate provide API same like actix. But all api is async include handler.
Service
Service is a Actor in Actor Model.
We can impl an Service on an struct to delcare an Service.
The Service provide hook named started and stopped, them all are async.
Please use async_trait macros.
Start Service
Start a service is very simple, only create it and call start method.
let svc = Service1 ;
svc.start;
Note: this function must call in async function or after async runtime initialized. If not, it will panic.
Stop
When a service started, we can call stop method on context.
You can call this function in Service Hook or in Handler.
Handler and Mesaage
A service can sending an message to other service, or called by other service.
Message
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.
Handler
Impl Handler on service, we can make a service accept call from other service.
Handler also an async function, please use async_trait macros.
Address
When we start an service, we can get an address. We also can get it from Context.
Call and Send
The address can make call or send.
- Call means caller want to known the result.
- This is an async function
- When an service stop, caller will get
ServiceStoppedfrom Error.
- Send means caller don't care the result, so
- This is an plain function
- When an service stop, caller will get
ServiceStoppedfrom Error.