VoltSignal:Wait
Yields the current thread until the signal fires.
Syntax
VoltSignal:Wait() -> anyParameters
This method takes no parameters.
Returns
| Type | Description |
|---|---|
any | The arguments passed to Fire |
Description
VoltSignal:Wait pauses the current thread until the signal is fired. When the signal fires, the thread resumes and returns any arguments that were passed to Fire.
Example
local signal = VoltSignal.new()
-- In another thread, fire after 2 seconds
task.spawn(function()
task.wait(2)
signal:Fire("Data loaded!", 100)
end)
-- Wait for the signal
local message, value = signal:Wait()
print(message, value)
-- Output (after 2 seconds): Data loaded! 100Timeout Pattern
local signal = VoltSignal.new()
local result
local timedOut = false
task.spawn(function()
result = signal:Wait()
end)
task.spawn(function()
task.wait(5)
if not result then
timedOut = true
-- Handle timeout
end
end)Related Functions
VoltSignal:Fire- Fire the signalVoltSignal:Connect- Connect without yielding