refactor(streamingRequest): internal method for request functions

- TS package type inference for request functions.
- Type fix for Lua's waitFor callback.
- Lua request functions cannot return nil.
This commit is contained in:
Linden
2024-03-31 16:15:44 +11:00
parent e3ece4f337
commit 0f0c7a6591
10 changed files with 50 additions and 74 deletions

View File

@@ -1,23 +1,16 @@
---Load a model. When called from a thread, it will yield until it has loaded.
---@param model number | string
---@param timeout number? Approximate milliseconds to wait for the model to load. Default is 1000.
---@return number? model
---@return number model
function lib.requestModel(model, timeout)
if not tonumber(model) then model = joaat(model) end
---@cast model -string
if type(model) ~= 'number' then model = joaat(model) end
if HasModelLoaded(model) then return model end
if not IsModelValid(model) then
return error(("attempted to load invalid model '%s'"):format(model))
error(("attempted to load invalid model '%s'"):format(model))
end
RequestModel(model)
if not coroutine.isyieldable() then return model end
return lib.waitFor(function()
if HasModelLoaded(model) then return model end
end, ("failed to load model '%s'"):format(model), timeout)
return lib.streamingRequest(RequestModel, HasModelLoaded, 'model', model, timeout)
end
return lib.requestModel