NativeSignal: Once Synchronous
Listen for the next firing of a runtime-backed event, then disconnect the listener. Use it for one event, such as the first response on a connection. The handler is removed after that event, so later messages need another subscription.
Luau
NativeSignal:Once(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 | One-shot handler. The owning event determines its arguments. |
Returns
RBXScriptConnectionAn RBXScriptConnection.
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:Once(function(message)
print("Received:", message)
end)
socket:Send("example message")
task.wait(2)
listener:Disconnect()
socket:Close()