Signal
A simple and lightweight signal implementation for Roblox.
AcidSignal provides a familiar event-driven API with a thread pool, bound arguments, and connection management via a doubly linked list.
local Signal = require(path.to.AcidSignal)
local signal = Signal.new()
signal:Connect(function(value)
print("fired:", value)
end)
signal:Fire("hello") -- fired: hello
Functions
new
Creates a new signal.
local signal = Signal.new()
Connect
Signal:Connect(fn: (A...,V...) → (),--
The function to call when the signal fires
...: V...--
Extra arguments appended to every call
) → Connection<A...,V...>Connects a callback to the signal.
local connection = signal:Connect(function(value)
print("fired:", value)
end)
-- With bound args
local connection = signal:Connect(function(value, value2)
print(value, value2)
end, "hello")
signal:Fire("world") -- hello world
Once
Signal:Once(fn: (A...,V...) → (),--
The function to call when the signal fires
...: V...--
Extra arguments appended to every call
) → Connection<A...,V...>Connects a callback that automatically disconnects after the first fire.
signal:Once(function(value)
print("fired once:", value)
end)
Wait
Signal:Wait(timeout: number?--
Maximum seconds to wait. If reached, returns false.
) → (boolean,--
Whether the signal fired before the timeout
A...--
The arguments passed to Fire, or nil if timed out
)Yields the current thread until the signal fires.
-- without timeout
task.defer(function() signal:Fire("Example") end)
local value = signal:Wait()
print(value) -- "Example"
-- with timeout (returns nil if timed out)
local value = signal:Wait(1)
print(value) -- nil
Fire
Signal:Fire(...: A...--
Arguments to pass to all connected callbacks
) → ()Fires the signal, calling all connected callbacks via the thread pool. If reentrancy exceeds 256 recursive calls, a warning is emitted and the call is dropped.
signal:Fire("hello")
DisconnectAll
Signal:DisconnectAll() → ()Disconnects all connections from the signal.
signal:DisconnectAll()
Destroy
Signal:Destroy() → ()Alias for DisconnectAll.
signal:Destroy()