Expected behavior:
If a scene is unloaded while a WebRequest instance is still active, the instance should be disposed and the callback discarded.
What is happening:
In a script using the WebRequest API (WebRequest.custom, specific to my case), the callback is invoked whenever the response is received–even if the scene is not loaded.
Example:
--[[
This function will recursively execute until Tabletop Simulator is closed.
(Whether the scene is loaded, a different scene is loaded, you go back to the main menu, etc.)
]]
function pollEvents(index)
log("Polling event #"..index)
WebRequest.custom(
<any endpoint>,
"GET",
true,
nil,
<any headers>,
function(instance)
... -- Do stuff
-- The callback has scope to the entire script (at least)
pollEvents(index+1)
)
endReferenced from:
https://github.com/ABViney/just-poker/blob/cf501433f5e7a91fd79ee19bfc304bdb30a24728/tts/src/ServerClientConnection.lua#L192