Monotonic

Monotonic :: # (opaque)

A reading of a clock that only moves forward and is unaffected by wall-clock changes, for measuring elapsed time.

A reading has no meaning on its own: it counts from an unspecified, process-local origin, so there is no integer in or out. Only the difference between two readings is useful, as a Duration. Readings must not be persisted or compared across runs; use Utc for a point in calendar time.

start = Monotonic.now!()
work!()?
Stdout.line!("Completed in ${start.elapsed!().to_str()}")?
now! : () => Monotonic

Read the monotonic clock.

since : Monotonic, Monotonic -> Duration

The time from an earlier reading to this one: later.since(earlier).

Gives Duration.zero when earlier is in fact the later reading.

elapsed! : Monotonic => Duration

The time since this reading was taken: Monotonic.now!().since(start).

A deadline loop is start.elapsed!() < Duration.seconds(10).