NativeSignal: Connect Synchronous
Listen to a runtime-backed event, such as a WebSocket message or close event. Use it to process repeated events for as long as the owning resource is active. Keep the returned connection and disconnect it during cleanup.
Luau
NativeSignal:Connect(callback: Function) -> RBXScriptConnectionParameters
Call this method with a NativeSignal receiver. The colon supplies self implicitly; a dot call must pass the receiver explicitly.
| Parameter | Type | Description |
|---|---|---|
callback | Function | Event handler. The owning event determines its arguments. |
Returns
RBXScriptConnectionAn RBXScriptConnection that can be disconnected when no longer needed.
Usage notes
This is an event wrapper supplied by another API, not a separately constructed Signal.new object.
Example
Luau
-- Requires an echo server you control at this address.
local socket = WebSocket.connect("ws://127.0.0.1:8765")
local listener = socket.OnMessage:Connect(function(message)
print("Received:", message)
end)
socket:Send("example message")
task.wait(2)
listener:Disconnect()
socket:Close()