aboutsummaryrefslogtreecommitdiff
path: root/library/lullaby/thread.lua
diff options
context:
space:
mode:
authoramelia squires <[email protected]>2025-03-31 13:21:27 -0500
committeramelia squires <[email protected]>2025-03-31 13:21:27 -0500
commitb554d73eeabb96f23385b7b093d5609ff6105e99 (patch)
treed1adb6a4e3cdf9ae3c11920ac98d4ed54bae8cca /library/lullaby/thread.lua
parent9f173bca86bdba7635d725772e349249fa890eee (diff)
type definitions
Diffstat (limited to 'library/lullaby/thread.lua')
-rw-r--r--library/lullaby/thread.lua67
1 files changed, 67 insertions, 0 deletions
diff --git a/library/lullaby/thread.lua b/library/lullaby/thread.lua
new file mode 100644
index 0000000..1b0e89d
--- /dev/null
+++ b/library/lullaby/thread.lua
@@ -0,0 +1,67 @@
+---@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
+
+---contains data for the thread
+---@deprecated
+---@type lightuserdata
+async._ = nil
+
+---@async
+---@param fun fun(res: fun(...)): nil function to call, parameter will set a return value for the thread
+---@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
+
+---puts a value into a atomic thread-safe buffer
+---@param value any
+---@return buffer-table
+function thread.buffer(value) end
+
+---locks any thread reaching this lock id until a corresponding unlock is met
+---@param tid integer
+---@return nil
+function thread.lock(tid) end
+
+---unlocks a lock id
+---@param tid integer
+---@return nil
+function thread.unlock(tid) end
+
+---@deprecated
+function thread.testcopy() end
+
+return thread