mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 07:26:02 +01:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user