aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/lua/meta/async.lua
blob: 8f7232a001a61abead7954e65d0a35b2227ee191 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---@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