Don't allow closing after close
This commit is contained in:
parent
dfaecbfec7
commit
923b4654d1
|
@ -19,6 +19,7 @@ local function notEmpty(s)
|
|||
end
|
||||
|
||||
local ws = function (dict)
|
||||
local closed = false
|
||||
local onMessage = dict.onMessage or function(msg)
|
||||
print(msg)
|
||||
end
|
||||
|
@ -41,17 +42,13 @@ local ws = function (dict)
|
|||
})
|
||||
if not resp.Success then
|
||||
error("Error Sending Message: " .. resp.StatusCode .. " " .. resp.StatusMessage)
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function close()
|
||||
server:RequestAsync({
|
||||
["Url"] = BaseUrl .. "/api/close/" .. JobId .. "/" .. id,
|
||||
["Method"] = "DELETE"
|
||||
})
|
||||
end
|
||||
|
||||
local loop = coroutine.create(function()
|
||||
local loop = task.spawn(function()
|
||||
while wait(0.1) do
|
||||
print("poll")
|
||||
local response = server:RequestAsync({
|
||||
|
@ -72,7 +69,17 @@ local ws = function (dict)
|
|||
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)
|
||||
return {
|
||||
sendMessage = sendMessage,
|
||||
|
|
Loading…
Reference in a new issue