针对:先加载资源A,加载完A再加载资源B,加载完B再加载资源C。
现在加需求了,如果加载资源A的时间不超过3s,那说明当前设备性能不错,会额外再加载高品质资源A2,A3,然后再加载B。
local obj1 = PromiseV1.new() local time1 = os.time() AsyncLoadRes("ResA", function(textA) obj1:SetFinished(textA) end) local loadResB = function(textA, _obj2) print("ResA load finish") local deltaTime = os.time() - time1 if deltaTime < 3 then local obj1_1 = PromiseV1.new() AsyncLoadRes("ResA1", function(textA1) obj1_1:SetFinished(textA1) end) local loadResA2 = function(textA1, _obj1_2) print("ResA1 load finish") AsyncLoadRes("ResA2", function(textA2) _obj1_2:SetFinished(textA2) end) end local obj1_2 = obj1_1:Next(loadResA2) local loadResB = function(textA2, _obj1_3) print("ResA2 load finish") AsyncLoadRes("ResB", function(textB) _obj2:SetFinished(textB) end) end local obj1_3 = obj1_2:Next(loadResB) else AsyncLoadRes("ResB", function(textB) _obj2:SetFinished(textB) end) end end local obj2 = obj1:Next(loadResB) local loadResC = function(textB, _obj3) print("ResB load finish") AsyncLoadRes("ResC", function(textC) _obj3:SetFinished(textC) end) end local obj3 = obj2:Next(loadResC) local printContent = function(textC, _obj4) print("ResC load finish, all loaded") end local obj4 = obj3:Next(printContent)
上面代码的加载链情况
标签:obj1,function,end,SetFinished,lua,例子,promise,local,加载 From: https://www.cnblogs.com/sailJs/p/18362034