QuickSignal
A signal your module owns and fires itself.
QuickSignal.new() makes one. Connect calls a function on every Fire and Once on the next one only, each in its own thread, in connect order. WaitAsync(timeout?) waits for the next fire and gives its values, or nil after the timeout or when the run ends.
moduleModules
A built-in module: require("@shotsystem/QuickSignal") in a Luau file.
Example
--!strict
-- A signal a module owns and fires itself.
local QuickSignal = require("@shotsystem/QuickSignal")
local TimeService = require("@shotsystem/TimeService")
local restocked = QuickSignal.new()
local connection = restocked:Connect(function(name : string, count : number)
print("restocked " .. name .. ": " .. count)
end)
restocked:Once(function(name : string)
print("first restock: " .. name)
end)
restocked:Fire("Apple", 3)
restocked:Fire("Bread", 5)
connection:Disconnect()
restocked:Fire("Cheese", 0)
TimeService:After(0.1, function()
restocked:Fire("Milk", 2)
end)
local name, count = restocked:WaitAsync(2)
print("waited for " .. tostring(name) .. ": " .. tostring(count))
print("nothing fires: " .. tostring((restocked:WaitAsync(0.1))))restocked Apple: 3 first restock: Apple restocked Bread: 5 waited for Milk: 2 nothing fires: nil
Functions
| Name | Arguments | Returns | Description |
|---|---|---|---|
| QuickSignal.new | () | QuickSignal | A new signal. |
| QuickSignal:Connect | (action : Action) | Connection | Calls action on every Fire, in its own thread. |
| QuickSignal:Once | (action : Action) | Connection | Calls action on the next Fire only. |
| QuickSignal:Fire | (... : any) | () | Calls every connected action with the values, each in its own thread, in connect order. |
| QuickSignal:WaitAsync | (timeout : number?) | ...any | Waits for the next Fire and returns its values; nil after timeout seconds or when the run ends. |
Connection
| Name | Arguments | Returns | Description |
|---|---|---|---|
| connection:Disconnect | () | () | Stops the calls (a second call does nothing). |
A connection's fields
| Name | Type | Description |
|---|---|---|
| ID | string | |
| Disconnected | boolean | |
| Signal | QuickSignal |
QuickSignal's fields
| Name | Type | Description |
|---|---|---|
| Connections | {Connection} |
