Skip to main content

Module clock

Module clock 

Source
Expand description

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.

Structs§

Instant
A measurement of a monotonically nondecreasing clock. Opaque and useful only with Duration.
SystemTime
A measurement of the system clock, useful for talking to external entities like the file system or other processes.
SystemTimeError
An error returned from the duration_since and elapsed methods on SystemTime, used to learn how far in the opposite direction a system time lies.

Constants§

UNIX_EPOCH
An anchor in time which can be used to create new SystemTime instances or learn about where in time a SystemTime lies.

Functions§

process_id
The current process id, or 0 where there is no process (the browser).
to_local_datetime
A wall-clock time as a local chrono date-time.