nupp.time

nupp.time provides clocks and waits from the current host.

const time = nupp.time

const started = time.now()
time.sleep(50)
print(time.now() - started)  -- about 50

print(time.wallTime())       -- milliseconds since the Unix epoch

now is the clock durations and deadlines are measured in. It only moves forward and its zero is whatever the host picked, so one reading means nothing except against another. wallTime is calendar time and may jump backwards when the machine's clock is corrected. Never subtract two of those to measure how long something took.

Submodules

ModuleDescription
nupp.time.spiImplementation interfaces consumed during ordinary module initialization.

Module contents

Functions

FunctionKindDescription
nowfunctionReturns monotonic milliseconds, the domain durations and deadlines use.
sleepfunctionWaits for a finite, non-negative interval through the suspension context.
sleepUntilfunctionWaits until a non-negative deadline in the now domain.
wakeAtfunctionSchedules a callback for a non-negative deadline in the now domain.
wallTimefunctionReturns milliseconds since the Unix epoch.

Functions#

nowfunction#

const now: function(): number

Returns monotonic milliseconds, the domain durations and deadlines use.

Returns

TypeDescription
number

sleepfunction#

const sleep: function(milliseconds: number): nil

Waits for a finite, non-negative interval through the suspension context.

Arguments

NameTypeDescription
millisecondsnumber

Returns

TypeDescription
nil

Raises

TypeCondition
string

when the interval is invalid or cannot be scheduled

sleepUntilfunction#

const sleepUntil: function(deadline: number): nil

Waits until a non-negative deadline in the now domain.

A deadline already past returns without waiting.

Arguments

NameTypeDescription
deadlinenumber

Returns

TypeDescription
nil

Raises

TypeCondition
string

when the deadline is invalid or cannot be scheduled

wakeAtfunction#

const wakeAt: function(deadline: number, resume: function(boolean): nil): function(): nil

Schedules a callback for a non-negative deadline in the now domain.

Returns a function that when called cancels the scheduled callback. Registration itself does not suspend.

Arguments

NameTypeDescription
deadlinenumber
resumefunction(boolean): nil

Returns

TypeDescription
function(): nil

Raises

TypeCondition
string

when the deadline is invalid or cannot be scheduled

wallTimefunction#

const wallTime: function(): number

Returns milliseconds since the Unix epoch.

Returns

TypeDescription
number