mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-16 22:46:03 +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:
19
imports/streamingRequest/client.lua
Normal file
19
imports/streamingRequest/client.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
---@async
|
||||
---@package
|
||||
---@generic T : string | number
|
||||
---@param request function
|
||||
---@param hasLoaded function
|
||||
---@param assetType string
|
||||
---@param asset T
|
||||
---@param timeout? number
|
||||
---@param ... any
|
||||
---Used internally.
|
||||
function lib.streamingRequest(request, hasLoaded, assetType, asset, timeout, ...)
|
||||
if hasLoaded(asset) then return asset end
|
||||
|
||||
request(asset, ...)
|
||||
|
||||
return lib.waitFor(function()
|
||||
if hasLoaded(asset) then return asset end
|
||||
end, ("failed to load %s '%s'"):format(assetType), timeout)
|
||||
end
|
||||
Reference in New Issue
Block a user