Module service

Source
Expand description

§Services

Interlink uses services to represent asynchronous tasks that can hold their own state and communicate between each-other using messages and handlers.

You can derive the service trait using its derive macro or implement it manually to get access to the Service::started and Service::stopping functions.

With derive macro:

use interlink::prelude::*;

#[derive(Service)]
struct MyService {
    value: String,
}

Without derive macro. Both the started and stopping functions are optional

use interlink::prelude::*;

struct MyService {
    value: String,
}

impl Service for MyService {
    fn started(&mut self, ctx: &mut ServiceContext<Self>) {
        println!("My service is started")
    }
}

Then you can start your service using the Service::start function which will start the service in a tokio task and return you a Link to the service. Alternatively if you need access to the service context while creating your service you can use the Service::create function which provides the context.

See Link for what to do from here

Structs§

ServiceContext
Backing context for a service which handles storing the reciever for messaging and the original link for spawning copies

Traits§

Service
Trait implemented by structures that can be spawned as services and used by the app