Don't allow closing after close

This commit is contained in:
Christopher Cookman 2024-09-04 09:02:53 -06:00
parent dfaecbfec7
commit 923b4654d1
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

View file

@ -19,6 +19,7 @@ local function notEmpty(s)
end end
local ws = function (dict) local ws = function (dict)
local closed = false
local onMessage = dict.onMessage or function(msg) local onMessage = dict.onMessage or function(msg)
print(msg) print(msg)
end end
@ -41,17 +42,13 @@ local ws = function (dict)
}) })
if not resp.Success then if not resp.Success then
error("Error Sending Message: " .. resp.StatusCode .. " " .. resp.StatusMessage) error("Error Sending Message: " .. resp.StatusCode .. " " .. resp.StatusMessage)
return false
else
return true
end end
end end
local function close() local loop = task.spawn(function()
server:RequestAsync({
["Url"] = BaseUrl .. "/api/close/" .. JobId .. "/" .. id,
["Method"] = "DELETE"
})
end
local loop = coroutine.create(function()
while wait(0.1) do while wait(0.1) do
print("poll") print("poll")
local response = server:RequestAsync({ local response = server:RequestAsync({
@ -72,7 +69,17 @@ local ws = function (dict)
end end
end end
end) end)
coroutine.resume(loop)
local function close()
if closed then return end
closed = true
server:RequestAsync({
["Url"] = BaseUrl .. "/api/close/" .. JobId .. "/" .. id,
["Method"] = "DELETE"
})
task.cancel(loop)
end
game:BindToClose(close) game:BindToClose(close)
return { return {
sendMessage = sendMessage, sendMessage = sendMessage,