mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-23 06:05:24 +00:00
plugin: Prevent HTTP timeout cascading after session stop
This commit is contained in:
@@ -82,11 +82,16 @@ function ApiContext.new(baseUrl)
|
|||||||
__baseUrl = baseUrl,
|
__baseUrl = baseUrl,
|
||||||
__serverId = nil,
|
__serverId = nil,
|
||||||
__messageCursor = -1,
|
__messageCursor = -1,
|
||||||
|
__connected = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
return setmetatable(self, ApiContext)
|
return setmetatable(self, ApiContext)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ApiContext:disconnect()
|
||||||
|
self.__connected = false
|
||||||
|
end
|
||||||
|
|
||||||
function ApiContext:connect()
|
function ApiContext:connect()
|
||||||
local url = ("%s/api/rojo"):format(self.__baseUrl)
|
local url = ("%s/api/rojo"):format(self.__baseUrl)
|
||||||
|
|
||||||
@@ -132,7 +137,7 @@ function ApiContext:retrieveMessages()
|
|||||||
local function sendRequest()
|
local function sendRequest()
|
||||||
return Http.get(url)
|
return Http.get(url)
|
||||||
:catch(function(err)
|
:catch(function(err)
|
||||||
if err.type == Http.Error.Kind.Timeout then
|
if err.type == Http.Error.Kind.Timeout and self.__connected then
|
||||||
return sendRequest()
|
return sendRequest()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -109,12 +109,17 @@ function ServeSession:start()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
:catch(function(err)
|
:catch(function(err)
|
||||||
self:__setStatus(Status.Disconnected, err)
|
self:__stopInternal(err)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ServeSession:stop()
|
function ServeSession:stop()
|
||||||
self:__setStatus(Status.Disconnected)
|
self:__stopInternal()
|
||||||
|
end
|
||||||
|
|
||||||
|
function ServeSession:__stopInternal(err)
|
||||||
|
self:__setStatus(Status.Disconnected, err)
|
||||||
|
self.__apiContext:disconnect()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ServeSession:__setStatus(status, detail)
|
function ServeSession:__setStatus(status, detail)
|
||||||
|
|||||||
Reference in New Issue
Block a user