async.lua

---@meta async

local async = {}

---Wraps the provided function so it can be started in another thread.
---
--- Example:
--- ```lua
--- local a = require("async")
--- local u = require("Utils")
---
--- function asyncFunction()
---   a.wait(u.waitms(500))
--- end
---
--- a.sync(asyncFunction)()
--- ```
---@param func function The function to call from the new thread.
function async.sync(func) end

---@async
---Calls an async function and waits for it to finish. **Must** be called from async.sync().
---
--- Example:
--- ```lua
--- local a = require("async")
--- local u = require("Utils")
---
--- function asyncFunction()
---   a.wait(u.waitms(500))
---   a.wait(u.waitms(1000))
--- end
---
--- a.sync(asyncFunction)()
--- ```
---@param func any The function to call and wait for its result.
---@return any any The result of the function.
function async.wait(func) end

---@async
---Calls multiple async functions and waits for all of them to finish. **Must** be called from async.sync().
---
--- Example:
--- ```lua
--- local a = require("async")
--- local u = require("Utils")
---
--- function asyncFunction()
---   a.wait_all {
---     u.waitms(500),
---     u.waitms(1000),
---   }
--- end
---
--- a.sync(asyncFunction)()
--- ```
---@param funcs table The functions to call and wait for.
---@return table table The result of each of the functions as an array.
function async.wait_all(funcs) end

return async

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.