From e59344f2d3903b9643ff8d77064147dfabced117 Mon Sep 17 00:00:00 2001 From: ame Date: Wed, 1 May 2024 14:02:05 -0500 Subject: thread roadmap --- docs/net.md | 2 +- docs/readme.md | 4 ++-- docs/thread.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ readme.md | 2 ++ 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 docs/thread.md diff --git a/docs/net.md b/docs/net.md index 2c8ca45..28a7070 100644 --- a/docs/net.md +++ b/docs/net.md @@ -1,6 +1,6 @@ # net -## listen (PARTIALLY IMPLEMENTED) +## listen (mostly IMPLEMENTED) 'takes a function with 1 argument and a integer for a port diff --git a/docs/readme.md b/docs/readme.md index 14859a5..9427403 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -14,11 +14,11 @@ which makes a global llib table > llib = require "llib" > ``` -the table has many subtables, with related function in them, you can view them like so +the table has many subtables and functions, with related function in them, you can view them like so ```lua llib.io.pprint(llib) --pprint is a part of the io module, pprint meaning pretty print ``` -all subtables have a corresponding file in this directory, with info on its functions +all subtables and functions have a corresponding file in this directory on usage 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 diff --git a/readme.md b/readme.md index 9be2615..fcfca65 100644 --- a/readme.md +++ b/readme.md @@ -30,6 +30,8 @@ todo: * thread-safe wrapper object +* threads + ---- # credits -- cgit v1.2.3