Skip to content

Instantly share code, notes, and snippets.

@Raven24
Created February 10, 2017 21:58
Show Gist options
  • Save Raven24/fbaf46de799d6483120f4b23905ac059 to your computer and use it in GitHub Desktop.
Save Raven24/fbaf46de799d6483120f4b23905ac059 to your computer and use it in GitHub Desktop.
Rust tokio/futures playground
extern crate futures;
extern crate tokio_core;
use futures::{Future, Poll, Async};
use futures::stream::Stream;
use tokio_core::reactor::Core;
struct SendNotice;
impl Stream for SendNotice {
type Item = String;
type Error = io::Error;
fn poll(&mut self) -> Poll<Option<Self::Item>, io::Error> {
println!("polled...");
Ok(Async::Ready(Some("test".to_string())))
}
}
fn main() {
// create server event loop
let mut evt_loop = Core::new().unwrap();
let handle = evt_loop.handle();
// endless loop of polling and 'doing something'
let server = SendNotice {}.for_each( |val| {
println!("do something");
Ok(())
});
evt_loop.run(server).unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment