Volt

VoltConnection:Disconnect

Disconnects the connection from the signal.

Syntax

VoltConnection:Disconnect() -> ()

Parameters

This method takes no parameters.

Returns

This method does not return a value.

Description

VoltConnection:Disconnect removes the handler from the signal. After disconnecting, the handler will no longer be called when the signal fires.

Example

local signal = VoltSignal.new()

local connection = signal:Connect(function()
    print("This will only print once")
end)

signal:Fire()
-- Output: This will only print once

-- Disconnect the handler
connection:Disconnect()

signal:Fire()
-- No output - handler is disconnected

One-Time Connection Pattern

local signal = VoltSignal.new()

local connection
connection = signal:Connect(function(value)
    print("Received:", value)
    connection:Disconnect() -- Disconnect after first fire
end)

signal:Fire("First")  -- Output: Received: First
signal:Fire("Second") -- No output

Cleanup Pattern

local signal = VoltSignal.new()
local connections = {}

-- Store connections for cleanup
table.insert(connections, signal:Connect(function()
    print("Handler 1")
end))

table.insert(connections, signal:Connect(function()
    print("Handler 2")
end))

-- Cleanup all connections
for _, conn in ipairs(connections) do
    conn:Disconnect()
end

On this page