
---@class mqtt_ioloop_options*
---@field timeout? number Network operation timeout, in seconds.
---@field sleep? number Sleep time after each iteration, in seconds.
---@field sleep_function? fun(seconds:number) Custom sleep function.

---@class mqtt_ioloop_module*
---@type mqtt_ioloop_module*
local M = {}

---@class mqtt_ioloop_object*
---@field args mqtt_ioloop_options*
---@field clients table
---@field running boolean is running.
local mqtt_ioloop_object = {}

--- Create an IO loop instance.
---@param args? mqtt_ioloop_options* Create parameters.
---@return mqtt_ioloop_object* loop IO loop Example.
function M.create(args) end

--- Get the default IO loop.
---@param autocreate? boolean Whether to automatically create it, the default is true.
---@param args? mqtt_ioloop_options* Create parameters.
---@return mqtt_ioloop_object*? loop Default IO loop.
function M.get(autocreate, args) end

--- Add MQTT client or loop function.
---@param client mqtt_client_object*|function Client or loop function.
---@return boolean ok Whether it is successful or not.
---@return string? errMsg error message.
function mqtt_ioloop_object:add(client) end

--- Remove MQTT client or loop function.
---@param client mqtt_client_object*|function Client or loop function.
---@return boolean ok Whether it is successful or not.
---@return string? errMsg error message.
function mqtt_ioloop_object:remove(client) end

--- Execute a round of IO loop.
function mqtt_ioloop_object:iteration() end

--- Perform a short sleep when there is no network timeout in the previous round.
function mqtt_ioloop_object:can_sleep() end

--- Run until there are no more clients or loop functions.
function mqtt_ioloop_object:run_until_clients() end

return M
