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§
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.