Cancel & Timeout
Abort an in-flight request before its callback fires, or override the default timeout to control how long the client waits for a response.
Cancel
| Parameter | Type | Description |
|---|---|---|
requestId | number | The id returned by Get, Post, Put, or Delete when the request was made. |
Cancels a pending request. The callback will not be called. Has no effect if the response has already arrived — Cancel is safe to call at any time.
local id = network:Get("slow/resource", nil, function(res)
print(res.data)
end)
-- Cancel when the player closes the panel
closeButton.Activated:Connect(function()
network:Cancel(id)
end)
Cancel on player leave
A common pattern: cancel all pending work when the player leaves so cleanup callbacks don't run after the character is gone.
local ids = {}
ids[1] = network:Get("player/data", nil, function(res) UI:Load(res.data) end)
ids[2] = network:Get("shop/catalogue", nil, function(res) Shop:Load(res.data) end)
game.Players.LocalPlayer.AncestryChanged:Connect(function()
for _, id in ids do
network:Cancel(id)
end
end)
SetTimeout
| Parameter | Type | Description |
|---|---|---|
seconds | number | How long to wait for a response before treating the request as timed out. Default is 10 seconds. |
Sets the timeout for all subsequent requests on this network instance. The default is 10 seconds. Call once after getting the network object — it applies globally to this instance, not per-request.
local network = RoExpress.GetNetwork()
network:SetTimeout(5) -- wait up to 5 seconds before timing out
network:Get("player/data", nil, function(res)
if res.type == "timeout" then
UI:ShowError("Server took too long to respond")
else
UI:Load(res.data)
end
end)
What happens on timeout
When a request times out the callback fires with a response where res.type == "timeout". The data and status fields will be nil. Network automatically retries timed-out requests up to the configured maximum — by default 2 retries with exponential backoff — so the callback only fires after all retry attempts are exhausted.
network:Get("slow/endpoint", nil, function(res)
if res.type == "timeout" then
warn("Request timed out after retries")
return
end
-- handle success or error
end)
See also
← Network · Request Methods | methods that return a requestId · Async / Promise API | chainable request variants