Skip to content
SinisterRectus edited this page Feb 7, 2022 · 10 revisions

extends Emitter

Used to periodically execute code according to the ticking of the system clock instead of an arbitrary interval.

Constructor

Clock()

Methods Inherited From Emitter

emit(name, ...)

Parameter Type Optional
name string
... *

Emits the named event and a variable number of arguments to pass to the event callbacks.

This method only operates on data in memory.

Returns: nil


getListenerCount(name)

Parameter Type
name string

Returns the number of callbacks registered to the named event.

This method only operates on data in memory.

Returns: number


getListeners(name)

Parameter Type
name string

Returns an iterator for all callbacks registered to the named event.

This method only operates on data in memory.

Returns: function


on(name, fn)

Parameter Type
name string
fn function

Subscribes a callback to be called every time the named event is emitted. Callbacks registered with this method will automatically be wrapped as a new coroutine when they are called. Returns the original callback for convenience.

This method only operates on data in memory.

Returns: function


onSync(name, fn)

Parameter Type
name string
fn function

Subscribes a callback to be called every time the named event is emitted. Callbacks registered with this method are not automatically wrapped as a coroutine. Returns the original callback for convenience.

This method only operates on data in memory.

Returns: function


once(name, fn)

Parameter Type
name string
fn function

Subscribes a callback to be called only the first time this event is emitted. Callbacks registered with this method will automatically be wrapped as a new coroutine when they are called. Returns the original callback for convenience.

This method only operates on data in memory.

Returns: function


onceSync(name, fn)

Parameter Type
name string
fn function

Subscribes a callback to be called only the first time this event is emitted. Callbacks registered with this method are not automatically wrapped as a coroutine. Returns the original callback for convenience.

This method only operates on data in memory.

Returns: function


removeAllListeners(name)

Parameter Type
name string/nil

Unregisters all callbacks for the emitter. If a name is passed, then only callbacks for that specific event are unregistered.

This method only operates on data in memory.

Returns: nil


removeListener(name, fn)

Parameter Type
name string
fn function

Unregisters all instances of the callback from the named event.

This method only operates on data in memory.

Returns: nil


waitFor(name, timeout, predicate)

Parameter Type Optional
name string
timeout number
predicate function

When called inside of a coroutine, this will yield the coroutine until the named event is emitted. If a timeout (in milliseconds) is provided, the function will return after the time expires, regardless of whether the event is emitted, and false will be returned; otherwise, true is returned. If a predicate is provided, events that do not pass the predicate will be ignored.

This method only operates on data in memory.

Returns: boolean, ...


Methods

start(utc)

Parameter Type Optional
utc boolean

Starts the main loop for the clock. If a truthy argument is passed, then UTC time is used; otherwise, local time is used. As the clock ticks, an event is emitted for every os.date value change. The event name is the key of the value that changed and the event argument is the corresponding date table.

This method only operates on data in memory.

Returns: nil


stop()

Stops the main loop for the clock.

This method only operates on data in memory.

Returns: nil


Clone this wiki locally