Struct Backoff

Source
pub struct Backoff;
Expand description

Allows Consumer to set Connection on backoff state

§Examples

use actix::prelude::*;
use nsq_client::{Subscribe, Connection, Backoff, OnBackoff, OnResume, InFlight, Ready};
struct Consumer{
    conn: Addr<Connection>,
    backoff: bool,
};

impl Actor for Consumer {
    type Context = Context<Self>;
    fn started(&mut self, _: &mut Self::Context) {
        self.subscribe::<OnBackoff>(ctx, self.0.clone());
        self.subscribe::<OnResume>(ctx, self.0.clone());
        self.subscribe::<InFlight>(ctx, self.0.clone());
        self.conn.do_send(Ready(10));
        self.conn.do_send(Backoff);
    }
}

impl Handler<OnBackoff> for Consumer {
    type Result = ();
    fn handle(&mut self, msg: OnBackoff, _: &mut Self::Context) {
        println!("Connection in Backoff");
        self.backoff = true;
    }
}

impl Handler<OnResume> for Consumer {
    type Result = ();
    fn handle(&mut self, msg: OnResume, _: &mut Self::Context) {
        println!("Connection resuming from backoff");
        self.backoff = false;
    }
}

impl Handler<OnInflight> for Consumer {
    type Result = ();
    fn handle(&mut self, msg: OnInFlight, _: &mut Self::Context) {
        match msg.0 {
            0 => { println!("backoff state: {}", self.backoff) },
            1 => { println!("resuming from backoff") },
            _ => { println!("throttle") },
        }
    }
}

Trait Implementations§

Source§

impl Handler<Backoff> for Connection

Source§

type Result = ()

The type of value that this handle will return
Source§

fn handle(&mut self, _msg: Backoff, ctx: &mut Self::Context)

Method is called for every message received by this Actor
Source§

impl Message for Backoff

Source§

type Result = ()

The type of value that this message will resolved with if it is successful.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Erased for T