Skip to the content.

Signal

local Signal = require(Packages.Constella.Signal)

local damaged = Signal.new()
local connection = damaged:Connect(function(target, amount) print(target, amount) end)
damaged:Fire("Dummy", 10)
connection:Disconnect()

Guarantees

API

Member Description
Signal.new(options?) options.OnError: (message: string) -> ()
signal:Connect(fn) Returns a Connection
signal:Once(fn) Disconnects after the first call
signal:Wait() Yields until the next Fire and returns its arguments
signal:Fire(...) Does nothing once the signal is destroyed
signal:DisconnectAll()  
signal:Destroy() Disconnects everything. Idempotent. Connect/Wait raise afterwards
signal:GetConnectionCount() Counts the connected listeners (it walks the list, so Connect and Disconnect don’t have to keep a count)
signal:IsDestroyed()  
connection.Connected boolean
connection:Disconnect() / :Destroy() Idempotent
Signal.is(value) Type check

Types: Signal.Signal<T...> and Signal.Connection.

Limitations