DaemonHandler

Trait DaemonHandler 

Source
pub trait DaemonHandler:
    Send
    + Sync
    + 'static {
    type Command: for<'de> Deserialize<'de> + Send;
    type Response: Serialize + Send + Sync;

    // Required method
    fn handle_command<'life0, 'async_trait>(
        &'life0 mut self,
        cmd: Self::Command,
    ) -> Pin<Box<dyn Future<Output = HandleResult<Self::Response>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn on_tick<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_start(&mut self) { ... }
    fn on_shutdown(&mut self) { ... }
}
Expand description

Trait for implementing daemon command handlers

Implement this trait to define how your daemon handles commands and periodic ticks.

Required Associated Types§

Source

type Command: for<'de> Deserialize<'de> + Send

The command type this daemon accepts

Source

type Response: Serialize + Send + Sync

The response type this daemon returns

Required Methods§

Source

fn handle_command<'life0, 'async_trait>( &'life0 mut self, cmd: Self::Command, ) -> Pin<Box<dyn Future<Output = HandleResult<Self::Response>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle an incoming command

This method is called whenever a client sends a command. Return HandleResult::Response to continue running, or HandleResult::Shutdown to stop the daemon after sending the response.

Provided Methods§

Source

fn on_tick<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called periodically based on the tick interval

Use this for background tasks like checking timers, cleaning up resources, etc. The default implementation does nothing.

Source

fn on_start(&mut self)

Called when the daemon starts, before accepting connections

Use this for initialization that needs to happen after the socket is created. The default implementation does nothing.

Source

fn on_shutdown(&mut self)

Called when the daemon is shutting down

Use this for cleanup tasks. The default implementation does nothing.

Implementors§