Skip to content

Clock

The clock the stub world runs on. "real" leaves std_polyfills alone; "virtual" swaps task and datetime on the shared table so one virtual second takes VIRTUAL_TIME_SCALE real seconds.

Clock.mode  :: string

Whether the clock runs at real speed or 100x.

Clock.originalTask  :: any

The task table captured before the virtual clock was installed.

Clock.originalDatetime  :: any

The datetime table captured before the virtual clock was installed.

Clock.polyfills  :: any

The std_polyfills table this clock swaps.

Clock.startClock  :: number

os.clock() when the clock was made.

Clock.startUnixTimestampMillis  :: number

The unix timestamp in milliseconds when the clock was made.

Clock : now ( )  -> number

Seconds since the clock was made, real or virtual by mode.

Returns

number
Clock : wait ( seconds )  -> number

Sleeps seconds of the clock's time and returns the time that passed on this clock, like task.wait: at least seconds, and more when the scheduler was late.

Parameters

seconds: number?

Returns

number
Clock : waitFor ( predicate ,  seconds )  -> boolean

Polls predicate every quarter second of the clock's time until it returns a truthy value or seconds of the clock's time pass. Returns whether the predicate turned truthy in time.

Parameters

predicate: () -> any
seconds: number

Returns

boolean
Clock : install ( )  -> ()

Swaps std_polyfills.task and std_polyfills.datetime for this clock. A real clock does nothing.

Clock : uninstall ( )  -> ()

Puts the real task and datetime back. Safe to call twice.

Clock . new ( mode ,  polyfills )  -> Clock

Makes a clock. "real" is the default.

Parameters

mode: "real" | "virtual"?
polyfills: any?

Returns

Clock