Mercurial > templog
view rust/src/sensor.rs @ 588:038734052b20 rust
fiddling with futures-rs instead
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 16 Dec 2016 01:10:57 +0800 |
parents | 646f03870762 |
children | dccd8504aa38 |
line wrap: on
line source
extern crate tokio_core; extern crate futures; use std::time::Duration; use std; use std::cell::RefCell; use tokio_core::reactor::Interval; use tokio_core::reactor::Core; use tokio_core::reactor::Handle; use futures::Stream; use futures::Future; pub struct Readings { } pub struct Sensor { } impl Sensor { fn step(self) -> Readings { return Readings {} } pub fn new() -> Sensor { Sensor {} } pub fn run(handle: &Handle) -> Box<Future<Item=Readings, Error = std::io::Error>> { let s = Sensor::new(); Interval::new(Duration::from_millis(400), handle).map(|()| { println!("each one"); // s.step() Readings {} }).boxed() } }