Returns the event loop where the task is running on
Returns:
Type Description EventLoopThe EventLoop.
Parameter Type Required Description obj table✕ The table to turn into an EventLoop. Creates a new instance of EventLoop: an object that runs tasks concurrently (pseudo-paralellism)
EventLoop.tasks_index might be lower than the quantity of items in the EventLoop.tasks list. You must trust tasks_index.
EventLoop.removed_index might be lower than the quantity of items in the EventLoop.removed list. You must trust removed_index.
The tasks might run in a different order than the one they acquire once you run EventLoop:add_task
Returns:
Type Description EventLoopThe EventLoop. Table structure:
{ timers = TimerList, -- A list of the timers the EventLoop will handle tasks = {}, -- The list of tasks the EventLoop is running removed = {}, -- The list of indexes in the tasks list to remove tasks_index = 0, -- The tasks list pointer removed_index = 0, -- The removed list pointer error_handler = nil -- The error handler. It must be a function (which receive the error and the task), and if it returns a Task it will be awaited. }
Parameter Type Required Description callback Timer✔ The timer that is being executed @
callbackparameter's structure:
Index Type Required Description task Task✔ The task to execute. This function is called when a timer executes. It adds the timer task to the EventLoop.
This function doesn't use all the Timer arguments. Passsing the ones listed here is enough.
This function shouldn't be called by the user code, it should be called by timers only.
Parameter Type Required Description callback Timer✔ The timer that is being executed @
callbackparameter's structure:
Index Type Required Description awaitable Future,Task✔ The awaitable to cancel. This function is called when an awaitable times out.
This function doesn't use all the Timer arguments. Passsing the ones listed here is enough.
This function shouldn't be called by the user code, it should be called by timers only.
Parameter Type Required Description delay number✔ The time to sleep This function pauses the current task execution and resumes it after some time.
Parameter Type Required Description delay number✔ The time to wait until the task can be appended task Task✔ The task to append no_future boolean✕ Either to cancel the creation or not a Future object that will return after the task ends. (default = false.) This function appends the given task to the EventLoop list after some time.
Returns:
Type Description FutureReturns the Future object if no_future is false.
Parameter Type Required Description when number✔ The time when the task will be resumed The same as EventLoop:sleep, but with an absolute time.
Parameter Type Required Description when number✔ The time when the task can be appended task Task✔ The task to append no_future boolean✕ Either to cancel the creation or not a Future object that will return after the task ends. (default = false.) The same as EventLoop:call_soon, but with an absolute time.
Returns:
Type Description FutureReturns the Future object if no_future is false.
Parameter Type Required Description task Task✔ The task to append Adds a task to run on the next loop iteration.
Parameter Type Required Description object Future,Lock,Event,Queue✔ The object class vararg mixed✔ The object arguments Creates a new asyncio object that belongs to this EventLoop
Returns:
Type Description mixedThe new object
Pauses the task execution. This can be called from inside the task only.
The task doesn't resume again if you don't append it back later. If you don't do it, this will just stop forever the task execution.
Checks if an object is awaitable or not.
Returns:
Type Description booleanWhether the object is awaitable or not
Parameter Type Required Description aw Future,Task✔ The awaitable to wait. Awaits a Future or Task to complete. Pauses the current task and resumes it again once the awaitable is done.
Returns:
Type Description mixedThe Future or Task return values.
Parameter Type Required Description aw Future,Task✔ The awaitable to wait. Awaits a Future or Task to complete, but safely. Returns nil if an error happened.
Returns:
Type Description mixedThe awaitable return values, or nil if it had an error.
Parameter Type Required Description aw Future,Task✔ The awaitable to wait. Adds a timeout for an awaitable. Basically it cancels the awaitable once the timeout is reached.
Parameter Type Required Description aw Future,Task✔ The awaitable to wait timeout number✔ The timeout A shorthand method for add_timeout and await_safe.
Returns:
Type Description mixedThe Future or Task return values.
Parameter Type Required Description vararg Future,Task✔ The awaitables to wait Awaits many awaitables at once. Runs them concurrently, and requires a FutureSemaphore object to do so.
Returns:
Type Description FutureSemaphoreThe FutureSemaphore that will result once every awaitable is done.
Runs a loop iteration.
Parameter Type Required Description task Task✔ The task Schedules the task, adds a future and runs the loop until the task is done.
Returns:
Type Description mixedThe values the task returns
Parameter Type Required Description task Task✔ The task index int✔ The task index in the list, to be removed later. Handles a task error and calls EventLoop:remove_later
Parameter Type Required Description index int✔ The task to remove Schedules a task removal
Runs the tasks in the list only.
Removes the tasks that are waiting to be removed from the list.
Parameter Type Required Description obj table✕ The table to turn into an EventLoop. Creates a new instance of OrderedEventLoop: the same as EventLoop but respecting the tasks order.
This is different from EventLoop since here, tasks_index and the quantity of items of tasks match.
EventLoop.removed_index might be lower than the quantity of items in the EventLoop.removed list. You must trust removed_index.
The tasks orders is the one they acquire once you run OrderedEventLoop:add_task.
Returns:
Type Description OrderedEventLoopThe OrderedEventLoop. Table structure:
{ timers = TimerList, -- A list of the timers the EventLoop will handle tasks = {}, -- The list of tasks the EventLoop is running removed = {}, -- The list of indexes in the tasks list to remove tasks_index = 0, -- The tasks list pointer removed_index = 0 -- The removed list pointer }
Removes the tasks that are waiting to be removed from the list.
Parameter Type Required Description obj table,nil✔ The table to turn into an EventLoop. runtime int✔ The maximum runtime that can be used. reset int✔ How many time it needs to wait until the used runtime is resetted. Creates a new instance of LimitedEventLoop: the same as EventLoop but with runtime limitations
This inherits from EventLoopReturns:
Type Description LimitedEventLoopThe LimitedEventLoop. Table structure:
{ timers = TimerList, -- A list of the timers the EventLoop will handle tasks = {}, -- The list of tasks the EventLoop is running removed = {}, -- The list of indexes in the tasks list to remove tasks_index = 0, -- The tasks list pointer removed_index = 0, -- The removed list pointer runtime = runtime, -- The maximum runtime reset = reset, -- The reset interval used = 0, -- The used runtime initialized = 0, -- When was the last runtime reset step = 0 -- The iteration step (0 -> needs to run timers, 1 -> needs to run tasks, 2 -> needs to remove tasks) }
Parameter Type Required Description now int✔ How many runtime is being used and not counted in LimitedEventLoop.used Checks if the EventLoop can run something.
Returns:
Type Description booleanWhether it can run something or not
Runs (or partially runs) a loop iteration if it is possible.
Parameter Type Required Description eventloop table✔ The table to turn into the mix vararg EventLoop✔ The classes to mix Creates a new object which is a mix of any EventLoop's variants.
Returns:
Type Description EventLoopThe mixed event loop.
