forked from zeng-github01/OC-Doc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththread.lua
More file actions
82 lines (68 loc) · 2.91 KB
/
thread.lua
File metadata and controls
82 lines (68 loc) · 2.91 KB
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
---@meta
--- Static thread API from `require("thread")`
---@class ThreadLib
local ThreadLib = {}
--- Starts a new thread executing the given function.
--- The thread runs autonomously and returns a thread handle.
---@param thread_proc fun(...): any Function to run in the thread
---@param ... any Optional arguments passed to thread_proc
---@return ThreadHandle Thread handle object
function ThreadLib.create(thread_proc, ...) end
--- Waits for all threads in the array to complete.
--- Optionally times out after `timeout` seconds.
---@param threads ThreadHandle[] Array of thread handles
---@param timeout number? Optional timeout in seconds
---@return boolean Success
---@return string|nil Error message on failure
function ThreadLib.waitForAll(threads, timeout) end
--- Waits for any one thread in the array to complete.
--- Optionally times out after `timeout` seconds.
---@param threads ThreadHandle[] Array of thread handles
---@param timeout number? Optional timeout in seconds
---@return boolean Success
---@return string|nil Error message on failure
function ThreadLib.waitForAny(threads, timeout) end
--- Returns the current thread handle.
--- Returns nil if called from the init process.
---@return ThreadHandle|nil Current thread handle
function ThreadLib.current() end
--- Thread handle object returned by `thread.create`
---@class ThreadHandle
local ThreadHandle = {}
--- Suspends the thread.
--- Suspended threads ignore events and do not resume until explicitly resumed.
---@return boolean Success
---@return string|nil Error message on failure
function ThreadHandle:suspend() end
--- Resumes a suspended thread.
--- Exceptions inside the thread are not propagated.
---@return boolean Success
---@return string|nil Error message on failure
function ThreadHandle:resume() end
--- Terminates the thread immediately.
--- All event listeners and child threads are also terminated.
---@return boolean Success
---@return string|nil Error message on failure
function ThreadHandle:kill() end
--- Returns the current status of the thread.
--- One of: `"running"`, `"suspended"`, `"dead"`
---@return string Thread status
function ThreadHandle:status() end
--- Attaches the thread to a parent process.
--- Prevents the parent from closing until this thread dies.
---@param level number? Optional process level (default: current process)
---@return boolean Success
---@return string|nil Error message on failure
function ThreadHandle:attach(level) end
--- Detaches the thread from its parent.
--- Allows the parent process to close independently.
---@return ThreadHandle|nil Self on success
---@return string|nil Error message on failure
function ThreadHandle:detach() end
--- Blocks until the thread is no longer running.
--- Optionally times out after `timeout` seconds.
---@param timeout number? Optional timeout in seconds
---@return boolean Success
---@return string|nil Error message on failure
function ThreadHandle:join(timeout) end
return ThreadLib