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.
Summary
Properties
Clock.mode :: stringClock.originalTask :: anyClock.originalDatetime :: anyClock.polyfills :: anyClock.startClock :: numberClock.startUnixTimestampMillis :: numberProperties
Section titled “Properties”Whether the clock runs at real speed or 100x.
originalTask
Section titled “originalTask”The task table captured before the virtual clock was installed.
originalDatetime
Section titled “originalDatetime”The datetime table captured before the virtual clock was installed.
polyfills
Section titled “polyfills”The std_polyfills table this clock swaps.
startClock
Section titled “startClock”os.clock() when the clock was made.
startUnixTimestampMillis
Section titled “startUnixTimestampMillis”The unix timestamp in milliseconds when the clock was made.
Methods
Section titled “Methods”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.
waitFor
Section titled “waitFor”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.
install
Section titled “install”Clock : install ( ) -> ()
Swaps std_polyfills.task and std_polyfills.datetime for this clock. A real clock does nothing.
uninstall
Section titled “uninstall”Clock : uninstall ( ) -> ()
Puts the real task and datetime back. Safe to call twice.
Functions
Section titled “Functions”Clock . new ( mode , polyfills ) -> Clock
Makes a clock. "real" is the default.
Parameters
| mode: "real" | "virtual"? | |
| polyfills: any? |
Returns
| Clock |