bach/
environment.rs

1use core::task::Poll;
2
3pub mod default;
4mod macrostep;
5#[cfg(feature = "net")]
6pub mod net;
7pub use macrostep::Macrostep;
8
9pub trait Environment {
10    fn enter<F: FnOnce(u64) -> O, O>(&mut self, f: F) -> O;
11
12    fn on_microsteps<F: FnMut(u64) -> usize>(&mut self, mut f: F) {
13        self.enter(|current_ticks| while f(current_ticks) > 0 {})
14    }
15
16    fn on_macrostep(&mut self, macrostep: Macrostep) -> Macrostep {
17        macrostep
18    }
19
20    fn close<F>(&mut self, close: F)
21    where
22        F: 'static + FnOnce() + Send,
23    {
24        self.enter(|_| close());
25    }
26}
27
28pub trait Runnable: 'static + Send {
29    fn run(self) -> Poll<()>;
30}