-
Notifications
You must be signed in to change notification settings - Fork 145
Clock
extends Emitter
Used to periodically execute code according to the ticking of the system clock instead of an arbitrary interval.
Methods Inherited From Emitter
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
Parameter | Type |
---|---|
name | string |
Returns the number of callbacks registered to the named event.
This method only operates on data in memory.
Returns: number
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
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
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
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
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
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
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
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, ...
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
Stops the main loop for the clock.
This method only operates on data in memory.
Returns: nil