Updated Thread (markdown)

Robert Jelic
2022-05-03 18:06:33 +02:00
parent 5746ae652d
commit 6a70a17a66

@@ -1 +1,39 @@
WIP
Threads are "functions" you can execute simultaneously. Ofc the reality is, i am just using coroutine for that. But it works pretty good AND is very easy to use.
<br>
Here is a list of all available functions for threads: <br>
## start
sets the time the timer should wait after calling your function
````lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aThread = mainFrame:addThread("myFirstThread"):show()
local function randomThreadFunction()
while true do
basalt.debug("Thread is active")
os.sleep(1) -- a sleep/coroutine.yield() or pullEvent is required otherwise we will never come back to the main program (error)
end
end
aThread:start(randomThreadfunction)
````
**parameters:**function func<br>
**returns:** self<br>
## getStatus
gets the thread status
````lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aThread = mainFrame:addThread("myFirstThread"):show()
basalt.debug(aThread:getStatus()) -- returns "running", "normal", "suspended" or "dead"
````
**parameters:** -<br>
**returns:** string "running" - if its running, "normal" - is active but not running (waiting for a event), "suspended" - is suspended<br>
## stop
stops the thread
````lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aThread = mainFrame:addThread("myFirstThread"):show()
basalt.debug(aThread:getStatus()) -- returns "running", "normal", "suspended" or "dead"
````
**parameters:** -<br>
**returns:** self<br>