Created
December 6, 2018 18:04
-
-
Save Isan-Rivkin/5c56a2499b9561b9389b70e5e821761a to your computer and use it in GitHub Desktop.
core-control
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
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