Clock - truemedian/Discordia GitHub Wiki

Inherits Emitter

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

Methods

start
stop

Inherited from Emitter
on
once
onSync
onceSync
emit
getListeners
getListenerCount
removeListener
removeAllListeners
waitFor

Methods

:start( [ utc ] )

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.

Name Type Optional
utc boolean x

Returns: nil

:stop( )

Stops the main loop for the clock.

Returns: nil

Inherited from Emitter

:on( name, fn )

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.

Name Type
name string
fn function

Returns: function

:once( name, fn )

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.

Name Type
name string
fn function

Returns: function

:onSync( name, fn )

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.

Name Type
name string
fn function

Returns: function

:onceSync( name, fn )

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.

Name Type
name string
fn function

Returns: function

:emit( name, [ ... ] )

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

Name Type Optional
name string
... * x

Returns: nil

:getListeners( name )

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

Name Type
name string

Returns: function

:getListenerCount( name )

Returns the number of callbacks registered to the named event.

Name Type
name string

Returns: number

:removeListener( name )

Unregisters all instances of the callback from the named event.

Name Type
name string

Returns: nil

:removeAllListeners( name )

Unregisters all callbacks from the named event.

Name Type
name string

Returns: nil

:waitFor( name, [ timeout ], [ predicate ] )

When called inside of a coroutine, this will yield the coroutine until the specific named event is emitted or until a timeout (in milliseconds) expires. If the coroutine is resumed by the event, then true is returned with any event arguments. If the coroutine is resumed by the timeout's expiration, then false is returned without any other arguments.

Name Type Optional Optional
name string
timeout number x
predicate function x

Returns: boolean, ...

⚠️ **GitHub.com Fallback** ⚠️