Skip to content

Instantly share code, notes, and snippets.

@Cobrand
Created August 17, 2016 22:38
Show Gist options
  • Save Cobrand/5a7a9e175da8c50b3767e21c3df4dc14 to your computer and use it in GitHub Desktop.
Save Cobrand/5a7a9e175da8c50b3767e21c3df4dc14 to your computer and use it in GitHub Desktop.
extern crate iron;
use std::sync::mpsc::* ;
use iron::prelude::*;
use iron::{Listening,status};
fn main() {
let (tx,rx) = channel() ;
let handler = move |request: &mut Request| {
let tx = tx.clone();
tx.send(5i32);
Ok(Response::with(status::Ok))
};
let listening = Iron::new(handler).http("0.0.0.0:8080").unwrap();
loop {
if let Ok(value) = rx.try_recv() {
// do something
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment