Skip to content

Instantly share code, notes, and snippets.

@Isan-Rivkin
Created December 6, 2018 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Isan-Rivkin/5c56a2499b9561b9389b70e5e821761a to your computer and use it in GitHub Desktop.
Save Isan-Rivkin/5c56a2499b9561b9389b70e5e821761a to your computer and use it in GitHub Desktop.
core-control
use std::sync::Arc;
use zmq;
use tokio;
use futures::{Future, Stream};
use tokio_zmq::{prelude::*, Rep};
use rand::{self,Rng};
use std::{thread, time};
#[derive(Debug)]
enum Error {
NotEnoughMessages,
TooManyMessages,
}
pub fn run() {
let ctx = Arc::new(zmq::Context::new());
let rep = Rep::builder(ctx)
.bind("tcp://*:5555")
.build()
.unwrap();
let (sink, stream) = rep.sink_stream().split();
let runner = stream
.map(|multipart| {
// let num = rand::thread_rng().gen_range(1000, 1000*2);
// println!("sleeping for {} ",num );
// thread::sleep(time::Duration::from_millis(num));
for msg in &multipart{
if let Some(msg) = msg.as_str(){
println!("forwarding : {}", msg);
}
}
// ecall....
// store the result ... .
multipart
}).forward(sink);
let f = runner.map(|_| ())
.or_else(|e| {
println!("Error: {:?}", e);
Ok(())
});
tokio::run(f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment