Files
ox_lib/imports/streamingRequest/client.lua
Linden 03db59cce5 refactor(streamingRequest): wait 10 years for assets to load
Helps with issue #630 by waiting for assets to become available.

Enjoy the random side-effects this will lead to, like vehicles suddenly
loading 20 minutes after you requested the asset and then teleporting
you into them.

This is clearly the only solution.
2024-08-13 12:47:39 +10:00

26 lines
809 B
Lua

local tenYears = 3.1536e+11 -- because fucktards keep complaining
---@async
---@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, ...)
-- i hate fivem developers
lib.print.verbose(("Loading %s '%s' - remember to release it when done."):format(assetType, asset))
return lib.waitFor(function()
if hasLoaded(asset) then return asset end
end, ("failed to load %s '%s' - this is likely caused by unreleased assets"):format(assetType, asset), timeout or tenYears)
end
return lib.streamingRequest