BackgroundService

Trait BackgroundService 

Source
pub trait BackgroundService: Send + Sync {
    // Required method
    fn start(
        &self,
    ) -> impl Future<Output = Result<Receiver<Result<(), Error>>, Error>> + Send;
}
Expand description

A background service to be handled by a BlueprintRunner

§Usage

use blueprint_runner::BackgroundService;
use blueprint_runner::error::RunnerError;
use tokio::sync::oneshot::{self, Receiver};

// A dummy background service that immediately returns
#[derive(Clone)]
pub struct FooBackgroundService;

impl BackgroundService for FooBackgroundService {
    async fn start(&self) -> Result<Receiver<Result<(), RunnerError>>, RunnerError> {
        let (tx, rx) = oneshot::channel();
        tokio::spawn(async move {
            let _ = tx.send(Ok(()));
        });
        Ok(rx)
    }
}

Required Methods§

Source

fn start( &self, ) -> impl Future<Output = Result<Receiver<Result<(), Error>>, Error>> + Send

Start this background service

This method returns a one-shot Receiver, that is used to indicate when the service stops running, either by finishing (Ok(())) or by error (Err(e)).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§