use futures::task::{Context, Poll};
pub trait ScheduledJob : Send {
fn run(&mut self, context: &mut Context) -> Poll<()>;
}
pub struct Job<TFn> {
action: Option<TFn>
}
impl<TFn> Job<TFn>
where TFn: Send+FnOnce() -> () {
pub fn new(action: TFn) -> Job<TFn> {
Job { action: Some(action) }
}
}
impl<TFn> ScheduledJob for Job<TFn>
where TFn: Send+FnOnce() -> () {
fn run(&mut self, _context: &mut Context) -> Poll<()> {
let action = self.action.take();
if let Some(action) = action {
action();
Poll::Ready(())
} else {
panic!("Cannot schedule an action twice");
}
}
}