Created
January 19, 2019 02:02
-
-
Save inferiorhumanorgans/972d48f4baaa92fb1d3ef49251ecc167 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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