Skip to content

Instantly share code, notes, and snippets.

@inferiorhumanorgans
Created January 19, 2019 02:02
Show Gist options
  • Save inferiorhumanorgans/972d48f4baaa92fb1d3ef49251ecc167 to your computer and use it in GitHub Desktop.
Save inferiorhumanorgans/972d48f4baaa92fb1d3ef49251ecc167 to your computer and use it in GitHub Desktop.
extern crate futures;
extern crate tokio_zmq;
extern crate zmq;
use futures::{Future, Sink, Stream};
use std::sync::Arc;
use tokio_zmq::{prelude::*, Multipart as MultipartMessage, Pub};
fn main() {
let ctx = Arc::new(zmq::Context::new());
let fut : Box<Future<Item = (), Error =()> + Send> = Box::new({
let sink = Pub::builder(Arc::clone(&ctx))
.connect("ipc:///tmp/socket")
.build()
.unwrap()
.sink(0);
let messages = vec![
MultipartMessage::from(
zmq::Message::from_slice(b"1234").unwrap()
),
MultipartMessage::from(
zmq::Message::from_slice(b"5678").unwrap()
),
];
let msg_iter = messages.into_iter();
let stream = futures::stream::iter_ok(msg_iter);
stream.fold(sink, |a, b| {
a.send(b).map_err(|_| ())
})
.map(|_| ())
});
tokio::run(fut)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment