oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1/// Timestamp used by [crate::sync::Awareness] to tag most recent updates.
2pub type Timestamp = u64;
3
4/// A clock trait used to obtain the current time.
5pub trait Clock: Send + Sync {
6 fn now(&self) -> Timestamp;
7}
8
9impl<F> Clock for F
10where
11 F: Fn() -> Timestamp + Send + Sync,
12{
13 #[inline]
14 fn now(&self) -> Timestamp {
15 self()
16 }
17}
18
19/// A clock which uses standard (non-monotonic) OS date time.
20#[cfg(not(target_family = "wasm"))]
21#[derive(Debug, Copy, Clone, Default)]
22pub struct SystemClock;
23
24#[cfg(not(target_family = "wasm"))]
25impl Clock for SystemClock {
26 fn now(&self) -> Timestamp {
27 std::time::SystemTime::now()
28 .duration_since(std::time::UNIX_EPOCH)
29 .unwrap()
30 .as_millis() as Timestamp
31 }
32}
33