1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! The monotonic and wall clocks, on every target NetGet builds for.
//!
//! `std::time::Instant::now()` and `SystemTime::now()` **panic** on `wasm32-unknown-unknown`
//! ("time not implemented on this platform"); the browser has clocks, std just does not know
//! how to reach them. On that target `Instant` is the tokio shim's `performance.now()` clock
//! and `SystemTime` is `web_time`'s `Date.now()`; on native both are std, so on native this
//! module changes nothing but a path.
//!
//! Use `crate::utils::clock::{Instant, SystemTime, UNIX_EPOCH}` rather than `std::time::*` in
//! anything the browser build compiles: `src/state`, `src/llm`, `src/protocol`, `src/cli`,
//! `src/tui`, the shared server modules and the protocols enabled in `crates/netget-web`. A
//! protocol that is only ever built natively can keep using std; the moment it is added to the
//! web build, every `Instant::now()` it reaches is a panic on first connection, so run the
//! rewrite in that direction rather than trusting it. `Duration` has no clock in it and stays
//! `std::time::Duration` everywhere.
pub use ;
// The monotonic clock is the tokio shim's (`crates/netget-tokio-wasm/src/time.rs`): the same
// type `tokio::time::sleep_until` takes, and offset so `Instant::now() - window` cannot
// underflow on a page that just loaded. The wall clock is `Date.now()` through `web-time`.
pub use Instant;
pub use ;
/// The current process id, or `0` where there is no process (the browser).
///
/// `std::process::id()` panics on `wasm32-unknown-unknown`; it is used here only to make
/// identifiers unique across NetGet processes, and there is one page per wasm instance.
/// A wall-clock time as a local `chrono` date-time.
///
/// `chrono` converts `std::time::SystemTime`; on wasm ours is `web_time`'s, so the conversion
/// goes through the epoch offset, which is target-neutral arithmetic.