Skip to content

l0.DependencyControl.Timer

Timer = require "l0.DependencyControl.Timer"
local Timer = require("l0.DependencyControl.Timer")

Timer

Timer with monotonic clock readings and millisecond sleep. Not affected by system clock changes.

Constructor

timer = Timer!
local timer = Timer()

Creates a new timer, running from the current time.

Instance methods

start

timer\start!
timer:start()

Resumes measurement from the current time. No-op if already running, so a prior stop/start round trip never discards accumulated time.

Returns:

  • self Timer — for chaining

stop

timer\stop!
timer:stop()

Pauses measurement, folding the elapsed interval into the accumulated total. No-op if already stopped.

Returns:

  • self Timer — for chaining

reset

timer\reset!
timer:reset()

Clears the accumulated time and restarts measuring from the current time, preserving the running/stopped state.

Returns:

  • self Timer — for chaining

Class methods

sleep

Timer.sleep ms
Timer.sleep(ms)

Sleeps for the given number of milliseconds.

param type description
ms number

getTime

Timer.getTime!
Timer.getTime()

Returns the current value of the process's monotonic clock, in milliseconds, at sub-millisecond resolution. Only differences between readings are meaningful.

Returns:

  • milliseconds number

Fields

field type description
elapsed number Milliseconds measured so far, excluding any intervals during which the timer was stopped. Read-only.