Differences compared to other signals:
Disconnect/DisconnectAll comes with a smart behavior by default when signal is firing (unless you specify the mode to be immediate), which defers current connection(s) to preserve snapshot behavior and immediately does nested connection(s)
local cn2 = nil
local cn = signal:Connect(function()
cn2 = signal:Connect(function()
end)
print(cn.Connected)
print(cn2.Connected)
signal:DisconnectAll()
print(cn.Connected)
print(cn2.Connected)
end)
signal:Fire()
print(cn.Connected)
print(cn2.Connected)
- Each connect method has a direct way to set priority (2nd argument after self), or you can change connection priority with
:ChangePriority(), this only has smart behavior
local cn = signal:Connect(function()
print("Foo")
end), 2)
cn:ChangePriority(4)
cn:ChangePriority()
local cn2 = signal:Connect(function()
print("Bar")
end), 3)
signal:Fire()
signal:PriorityFire()
- :
Wait() method has timeout and connectionPointer parameter, this gives more customization with the wait connection
local thisConnection = {}:: SomeSignal.Connection<...any>
task.delay(3, function()
thisConnection:ChangePriority(3)
end)
signal:Wait(12, nil, thisConnection)
- There's more disconnect methods,
:DisconnectNestedConnections(), :DisconnectCurrentConnections() and with ability to choose behavior you want (deferred, immediate) <- or both in :DisconnectNestedConnections() case
local nestedConnection = nil
local currentConnection = nil
currentConnection = signal:Connect(function()
nestedConnection = signal:Connect(function()
end)
signal:DisconnectCurrentConnections("immediate")
print(currentConnection.Connected)
print(nestedConnection.Connected)
signal:DisconnectNestedConnections("deferred")
print(nestedConnection.Connected)
end)
signal:Fire()
print(currentConnection.Connected)
print(nestedConnection.Connected)
:CancelAllMutations() lets you cancel all mutations done in the current Fire (except reentrant fires / immediate disconnects), it can either be deferred which is the default, immediate or both, useful for when you dont want mutations
local nestedConnection = nil
local currentConnection = nil
currentConnection = signal:Connect(function()
nestedConnection = signal:Connect(function()
while (true) do
print("BOO!")
signal:Fire()
end
end)
currentConnection:ChangePriority(3)
currentConnection:ChangePriority(54)
currentConnection:ChangePriority(29)
signal:DisconnectAll()
signal:CancelAllMutations("immediate")
signal:Fire()
end)
signal:Fire()
print(currentConnection.Priority)
print(currentConnection.Connected)
print(nestedConnection.Connected)
:SyncFire() and :SyncPriorityFire() lets you dispatch connections the fastest, but at cost of it not being yield safe, doesn’t respect if signal is firing and makes mutations immediate if fired outside of :Fire() (this is very important because changing priority / adding new connection during :SyncPriorityFire() can be devastating)
Special thanks to @silk parrot for helping with development of SomeSignal and releasing a Signal Certifications Guide <- Extra documentation can also be found there