ManagedProc

Trait ManagedProc 

Source
pub trait ManagedProc: Send + Sync {
    // Required method
    fn run_proc(self: Box<Self>, shutdown: ShutdownSignal) -> ManagedFuture;
}
Expand description

A trait for types that can be managed as long-running async tasks.

Implement this trait to make your type usable with Supervisor. The trait is also automatically implemented for closures of the form FnOnce(ShutdownSignal) -> Future<Output = ProcResult>.

§Example

use super_visor::{ManagedProc, ManagedFuture};

struct MyDaemon { /* ... */ }

impl ManagedProc for MyDaemon {
    fn start_task(self: Box<Self>, shutdown: ShutdownSignal) -> ManaagedFuture {
        super_visor::spawn(self.run_task_logic_in_some_loop(shutdown))
    }
}

Required Methods§

Source

fn run_proc(self: Box<Self>, shutdown: ShutdownSignal) -> ManagedFuture

Starts the process and returns a future that completes when the work is complete or runs indefinitely in a continual loop.

The shutdown listener will be triggered when the supervisor wants to shut down the process. Implementations should listen for this signal and clean up gracefully. Listening typically involves awaiting the shutdown signal alongside the primary operational logic of the managed task in a select function or macro, or checking the signal has completed or been cancelled at await points in the control loop

Implementors§

Source§

impl ManagedProc for Supervisor

Source§

impl<O, P> ManagedProc for P
where O: Future<Output = ProcResult> + Send + 'static, P: FnOnce(ShutdownSignal) -> O + Send + Sync,