Skip to main content
load(@std//time.axl, sleep, sleep_iter, monotonic, monotonic_ns, time)
function sleep
def sleep(ms: int) -> None
Blocks the current thread for ms milliseconds. Returns None. The sleep is synchronous; the calling task’s thread is parked for the full duration.

Examples

load("@std//time.axl", "sleep")
sleep(250)  # pause for 250 ms
function sleep_iter
def sleep_iter(ms: int) -> typing.Iterable[int]
Returns an infinite iterator that yields a monotonically increasing integer every ms milliseconds. Each call to next sleeps for ms milliseconds, then returns the next tick (starting at 0). Use break to stop iteration.

Examples

load("@std//time.axl", "sleep_iter")
for tick in sleep_iter(1000):  # poll once per second
    if check_done():
        break
function monotonic
def monotonic() -> float
Returns a monotonically non-decreasing time in seconds as a float. The reference epoch is fixed at process start, so values are only meaningful relative to other monotonic() readings within the same process. Suitable for measuring elapsed time.

Examples

load("@std//time.axl", "monotonic")
start = monotonic()
do_work()
elapsed = monotonic() - start  # seconds, as float
function monotonic_ns
def monotonic_ns() -> int
Returns a monotonically non-decreasing time in nanoseconds as an int. The reference epoch is fixed at process start, so values are only meaningful relative to other monotonic_ns() readings within the same process. Higher precision than monotonic().

Examples

load("@std//time.axl", "monotonic_ns")
start = monotonic_ns()
do_work()
elapsed_ns = monotonic_ns() - start  # nanoseconds, as int
property time
time: struct(monotonic = function, monotonic_ns = function, sleep = function, sleep_iter = function)