Created
February 10, 2017 21:58
-
-
Save Raven24/fbaf46de799d6483120f4b23905ac059 to your computer and use it in GitHub Desktop.
Rust tokio/futures playground
This file contains hidden or 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_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