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

Connect, fire, waitLuau
--!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))))
What it printedOutput
restocked Apple: 3
first restock: Apple
restocked Bread: 5
waited for Milk: 2
nothing fires: nil

Functions

NameArgumentsReturnsDescription
QuickSignal.new()QuickSignalA new signal.
QuickSignal:Connect(action : Action)ConnectionCalls action on every Fire, in its own thread.
QuickSignal:Once(action : Action)ConnectionCalls 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?)...anyWaits for the next Fire and returns its values; nil after timeout seconds or when the run ends.

Connection

NameArgumentsReturnsDescription
connection:Disconnect()()Stops the calls (a second call does nothing).

A connection's fields

NameTypeDescription
IDstring
Disconnectedboolean
SignalQuickSignal

QuickSignal's fields

NameTypeDescription
Connections{Connection}