Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shiawaseu/threading
Luau library for managing threads and signals
https://github.com/shiawaseu/threading
Last synced: about 2 months ago
JSON representation
Luau library for managing threads and signals
- Host: GitHub
- URL: https://github.com/shiawaseu/threading
- Owner: Shiawaseu
- Created: 2024-07-21T11:58:07.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2024-07-22T12:01:07.000Z (6 months ago)
- Last Synced: 2024-07-23T13:57:15.548Z (6 months ago)
- Language: Luau
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Threading
- Luau library for managing threads and signals.## Usage
```lua
-- Declare the library
local Library = loadstring(game:HttpGet("https://raw.githubusercontent.com/shiawaseu/threading/master/Threading.luau", true))()-- Example callback function
local function exampleCallback(...)
print("Callback:", ...)
end-- Run a while loop thread for callback with a delay
-- local thread = Library.CreateThread(1, exampleCallback, "test")-- Connect a callback to any Signal
local HBthread = Library.CreateThread(game:GetService("RunService").Heartbeat, exampleCallback, "Hello", "World")-- Getting threads
local activeThreads = Library:GetThreads()
for i, thread in pairs(activeThreads) do
print("Thread:", i, thread.FunctionName)
endprint(Library:IsActiveThread(HBthread)) -- Output: true
task.wait(1)
-- Shutting down threads
HBthread:Destruct()print(Library:IsActiveThread(HBthread)) -- Output: false
```
## Thread Object Reference
- `FunctionName `
- Function Name which was originally the callback name, `N/A` if the callback is anonymous- `Runtime `
- The seconds that have passed since [epoch](https://en.wikipedia.org/wiki/Epoch)- `ThreadAddressOrSignal `
- The thread the callback is running on if not a signal (delay loop) or the Signal the callback is connected to- ` Destruct(): `
## Library API Reference
- `Library.CreateThread(SignalOrDelay: | , callback: , ...: ): `
- Creates a thread with a delay or signal. Returns a `Thread` object.- ` Library:GetThreads(): `
- Returns a table of active threads.
- Destructed threads still remain, but no longer contain their thread/signal.- ` Library:GetThreadCount(): `
- Returns the count of active threads.- ` Library:IsActiveThread(thread: ) `
- Returns wether the provided `Thread` object is active & running or not.- ` Library:GetThreadRuntime(thread: ) `
- Returns the elapsed time since the thread has started.