I was hoping someone proficient with using promises and understanding thread lifetimes would be able to tell me if I’ve written this in a way that prevents infinitely hanging threads, as well as being robust?
function module.InvokeClient(player, requestName, timeout, ...)
local uuid = HTTPService:GenerateGUID(false)
local thisPromise = Promise.try(remoteFunction.InvokeClient, remoteFunction, uuid, requestName, ...)
local _conn; _conn = player.AncestryChanged:Connect(function(c, p)
if p ~= game:GetService("Players") then
thisPromise:cancel()
end
end)
thisPromise:timeout(timeout):catch(function(e)
if Promise.Error.isKind(e, Promise.Error.Kind.TimedOut) then
remoteEvent:FireClient(player, uuid)
end
end):finally(function(status)
if _conn then _conn:Disconnect() end
if status == Promise.Status.Cancelled then
remoteEvent:FireClient(player, uuid)
end
end)
return thisPromise
end