extern crate tokio;
extern crate futures;
extern crate tokio_timer;
use futures::{Future, stream, Stream, Sink};
use futures::future::lazy;
use futures::sync::mpsc;
use std::{thread,time};
fn main() {
let task = lazy(||{
let (tx,rx) = mpsc::channel(1024);
let fut = lazy(||{
stream::iter_ok(0..10).fold(tx,|tx, i| {
let t = time::Duration::from_millis(1500);
thread::sleep(t);
tx.send(format!("msg from task {}", i)).map_err(|e| {
println!("send error: {:?}", e)
})
})
});
tokio::spawn( fut ); // can not compile
rx.for_each(|msg| {
println!("Got {}", msg);
Ok(())
}).map_err(|e|{
println!("error: {:?}", e);
})
});
tokio::run(task);
}
lazy crate a future,
tokio::spawn takes a future as parameter right? so why can not compile?