Trait ElectionClient

pub trait ElectionClient:
    Send
    + Sync
    + 'static {
    // Required methods
    fn id(&self) -> Result<String, MetaError>;
    fn run_once<'life0, 'async_trait>(
        &'life0 self,
        ttl: i64,
        stop: Receiver<()>,
    ) -> Pin<Box<dyn Future<Output = Result<(), MetaError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn subscribe(&self) -> Receiver<bool>;
    fn leader<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Option<ElectionMember>, MetaError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn get_members<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<ElectionMember>, MetaError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn is_leader(&self) -> bool;

    // Provided method
    fn init<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), MetaError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait { ... }
}

Required Methods§

fn id(&self) -> Result<String, MetaError>

fn run_once<'life0, 'async_trait>( &'life0 self, ttl: i64, stop: Receiver<()>, ) -> Pin<Box<dyn Future<Output = Result<(), MetaError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Run the long-running election process.

Returns when the leader status is lost, or the stop signal is received.

fn subscribe(&self) -> Receiver<bool>

fn leader<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Option<ElectionMember>, MetaError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

fn get_members<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ElectionMember>, MetaError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

fn is_leader(&self) -> bool

Provided Methods§

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

Implementors§

§

impl ElectionClient for DummyElectionClient

§

impl<T> ElectionClient for SqlBackendElectionClient<T>
where T: SqlDriver + Send + Sync + 'static,