Module jls.lang.event

Returns the default event instance to execute asynchronous operations.

The Event class coordinates distinct asynchronous operations using a single event loop.

Class Event

Event:new () Creates an Event.
event:setTimeout (callback[, delayMs=0[, ...]]) Registers a timer which executes a function once after the timer expires.
event:clearTimeout (timer) Unregisters a timer.
event:setInterval (callback, delayMs) Registers a timer which executes a function repeatedly with a fixed time delay between each execution.
event:clearInterval (timer) Unregisters a timer.
event:loop () Runs the event loop until there is no more registered event.
event:stop () Stops the event loop.
event:loopAlive () Indicates whether or not this event has at least one registered event.
event:runOnce () Runs the event loop once.
event:close () Closes this event.


Class Event

An Event class.
Event:new ()
Creates an Event.
event:setTimeout (callback[, delayMs=0[, ...]])
Registers a timer which executes a function once after the timer expires.

Parameters:

  • callback function A function that is executed once after the timer expires
  • delayMs number The time, in milliseconds, the timer should wait before the specified function is executed (default 0)
  • ... The parameters to pass when calling the function (optional)

Returns:

    An opaque value identifying the timer that can be used to cancel it

Usage:

    event:setTimeout(function()
      -- something that have to be done once in 1 second
    end, 1000)
event:clearTimeout (timer)
Unregisters a timer.

Parameters:

  • timer the timer as returned by the setTimeout or setInterval method.
event:setInterval (callback, delayMs)
Registers a timer which executes a function repeatedly with a fixed time delay between each execution.

Parameters:

  • callback function A function that is executed repeatedly
  • delayMs number The time, in milliseconds, the timer should wait between to execution

Returns:

    An opaque value identifying the timer that can be used to cancel it

Usage:

    local intervalId
    intervalId = event:setInterval(function()
      -- something that have to be done every 1 second
      intervalId:clearInterval(intervalId)
    end, 1000)
event:clearInterval (timer)
Unregisters a timer.

Parameters:

  • timer The timer as returned by the setTimeout or setInterval method.
event:loop ()
Runs the event loop until there is no more registered event.
event:stop ()
Stops the event loop.
event:loopAlive ()
Indicates whether or not this event has at least one registered event.

Returns:

    boolean true when this event has something to do
event:runOnce ()
Runs the event loop once.
event:close ()
Closes this event.
generated by LDoc 1.4.6