Trait Subscribe

Source
pub trait Subscribe
where Self: Actor, <Self as Actor>::Context: AsyncContext<Self>,
{ // Provided method fn subscribe<M: NsqMsg>( &self, ctx: &mut Self::Context, addr: Arc<Addr<Connection>>, ) where Self: Handler<M>, <Self as Actor>::Context: ToEnvelope<Self, M> { ... } }
Expand description

Allows differents consumers to subscribe to the desired msgs sent by connections.

§Example

struct Consumer(pub Addr<Connection>);

impl Actor for Consumer {
    type Context = Context<Self>;
    fn started(&mut self, ctx: &mut Self::Context) {
        self.subscribe::<Msg>(ctx, self.0.clone());
        self.subsctibe::<InFligth>(ctx, self.0.clone());
    }
}

impl Handler<Msg> for Consumer {
    type Result = ();
    fn handle(&mut self, msg: Msg, _: &mut Self::Context) {
        // process Msg
    }
}

impl Handler<InFligth> for Consumer {
    type Result = ();
    fn handle(&mut self, msg: InFligth, _: &mut Self::Context) {
        // do something every time in_fligth is increased or decreased
    }
}

Provided Methods§

Source

fn subscribe<M: NsqMsg>( &self, ctx: &mut Self::Context, addr: Arc<Addr<Connection>>, )
where Self: Handler<M>, <Self as Actor>::Context: ToEnvelope<Self, M>,

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.

Implementors§

Source§

impl<A> Subscribe for A
where A: Actor, <Self as Actor>::Context: AsyncContext<A>,