aboutsummaryrefslogtreecommitdiff
path: root/library/lullaby/thread.lua
blob: 43e897d9fd83268880133fc035c8639dd51ecef6 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
---@meta

---@class thread
local thread = {}

---@class async-table
local async = {}

---waits for thread to exit, returns the value of res
---@param T async-table
---@return ...
function async.await(T) end

---calls thread __gc early
---@param T async-table
---@return nil
function async.clean(T) end

---waits for the thread to either call res:testcancel() or for it to exit
---@param T async-table
---@return nil
function async.close(T) end

---stops the thread forcefully, may cause problems, likely not thread-safe
---@param T async-table
---@return nil
function async.kill(T) end

---contains data for the thread
---@deprecated
---@type lightuserdata
async._ = nil

---@class async-res-table
---@overload fun(a: any): nil
local asyncres = setmetatable({}, {
  __call = function() end
})

---checks if the thread is being requested to close with thread:close()
---@param T async-res-table
---@return nil
function asyncres.testclose(T) end

---calls res:testclose every line
---@param T async-res-table
---@return nil
function asyncres.autoclose(T) end
---@meta

---@async
---@nodiscard
---@param fun fun(res: async-res-table): nil function to call, parameter will set a return value for the thread, also contains methods for thread managment
---@return async-table
function thread.async(fun) end

---@class buffer-table
local buffer = {}

---gets the value of the buffer
---@param T buffer-table
---@return any
function buffer.get(T) end

---sets the value of the buffer
---@param T buffer-table
---@param value any
---@return nil
function buffer.set(T, value) end

---calls a function with a parameter that is the value of the buffer, return the new value of the buffer
---@param T buffer-table
---@param fun fun(any): nil
---@return nil
function buffer.mod(T, fun) end

---@nodiscard
---puts a value into a atomic thread-safe buffer
---@param value any
---@return buffer-table
function thread.buffer(value) end

---@deprecated
function thread.testcopy() end

---@class mutex-table
local mutex = {}

---locks the mutex
---@param T mutex-table
---@return nil
function mutex.lock(T) end

---unlocks the mutex
---@param T mutex-table
---@return nil
function mutex.unlock(T) end

---frees the mutex, automatically called by __gc
---@param T mutex-table
---@return nil
function mutex.free(T) end

---returns a mutex object, useful for solving race conditions in multi-threaded environments
---@return mutex-table
function thread.mutex() end

---puts the thread to sleep for N microseconds
---@param N integer
function thread.usleep(N) end

---puts the thread to sleep for N seconds
---@param N number
function thread.sleep(N) end

return thread