[][src]Trait futures_zmq::prelude::WithEndHandler

pub trait WithEndHandler: Stream<Item = Multipart> {
    fn with_end_handler<E>(
        self,
        end_handler: E
    ) -> EndingStream<E, Self, Self::Error>
    where
        E: EndHandler
; }

This trait is provided to allow for ending a stream based on a Multipart message it receives.

Required methods

fn with_end_handler<E>(
    self,
    end_handler: E
) -> EndingStream<E, Self, Self::Error> where
    E: EndHandler

Add an EndHandler to a stream.

Example, using a Sub wrapper type

extern crate futures;
extern crate tokio_zmq;
extern crate zmq;

use std::sync::Arc;

use futures::{Future, Stream};
use tokio_zmq::{prelude::*, Sub, Multipart};

struct End(u32);

impl EndHandler for End {
    fn should_stop(&mut self, multipart: &Multipart) -> bool {
        self.0 += 1;

        self.0 > 30
    }
}

fn main() {
    let ctx = Arc::new(zmq::Context::new());
    let fut = Sub::builder(ctx)
        .bind("tcp://*:5571")
        .filter(b"")
        .build()
        .and_then(|sub| {
            sub.stream()
                .with_end_handler(End(0))
                .for_each(|_| Ok(()))
        });

    // tokio::run(fut.map(|_| ()).or_else(|e| {
    //     println!("Error: {}", e);
    //     Ok(())
    // }));
}
Loading content...

Implementors

impl<T> WithEndHandler for T where
    T: Stream<Item = Multipart>, 
[src]

Loading content...