forked from M-Labs/humpback-dds
eth clock: init
This commit is contained in:
parent
1821b55fc1
commit
05b056d273
19
examples/util/clock.rs
Normal file
19
examples/util/clock.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
use smoltcp::time::{Duration, Instant};
|
||||||
|
use core::cell::Cell;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Clock(Cell<Instant>);
|
||||||
|
|
||||||
|
impl Clock {
|
||||||
|
pub fn new() -> Clock {
|
||||||
|
Clock(Cell::new(Instant::from_millis(0)))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn advance(&self, duration: Duration) {
|
||||||
|
self.0.set(self.0.get() + duration)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn elapsed(&self) -> Instant {
|
||||||
|
self.0.get()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user