diff options
| author | ame <[email protected]> | 2024-05-01 14:02:05 -0500 |
|---|---|---|
| committer | ame <[email protected]> | 2024-05-01 14:02:05 -0500 |
| commit | e59344f2d3903b9643ff8d77064147dfabced117 (patch) | |
| tree | b33eac843e4086e3968dda48ccaec5f0a0d2e1f9 /docs/thread.md | |
| parent | 15a906def7194e84ea151f6bf1972fc7c1986fd4 (diff) | |
thread roadmap
Diffstat (limited to 'docs/thread.md')
| -rw-r--r-- | docs/thread.md | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/docs/thread.md b/docs/thread.md new file mode 100644 index 0000000..0d96809 --- /dev/null +++ b/docs/thread.md @@ -0,0 +1,64 @@ +# threads ** + +## llib.thread ** + +'takes a function which will be ran in a separate thread with a single parameter with thread info + +these have the same backend (and limitations) of network threads + +```lua +local thread = llib.thread(function(info) + local N = 0 + ... + return N; +end) +``` + +### thread function parameters + +as used with "info" above + +#### info:send() + +'takes "any" value + +send a value which can be retrieved from outside the thread with thread:next() + +```lua +info:send(5) +info:send("hello") +``` + +#### info:pause() + +pauses the thread (must be resumed from outside) + +### thread return object + +#### thread:await() + +'optional timeout + +waits for the thread to return, and returns whatever it returned, if timeout is exceeded nil + +```lua +thread:await() -- value of N (above) +``` + +#### thread:next() + +gets the most oldest value sent using info:send() and pops it + +```lua +--(continued from above) +thread:next() -- 5 +thread:next() -- "hello" +``` + +#### thread:kill() + +kills the thread + +#### thread:pause() thread:resume() + +stops or continues the thread |
