当前位置:网站首页>cocos中使用async await异步加载资源
cocos中使用async await异步加载资源
2022-08-02 02:17:00 【zfoo-framework】
async function main(){
let data = await fun1();
console.log(data);
}
async function fun1(){
return new Promise((resolve, reject)=>{
// 这里可以写代码回调的代码,最终使用resolve得到结果
resolve('Promise')
}
)
}
main();
对比下
async function start(){
let data = await fun1();
console.log(data);
let data2 = await fun2();
console.log(data2);
}
async function fun1(){
return new Promise((resolve, reject)=>{
setTimeout(()=>{
resolve('Promise func1')
}, 3000)
}
)
}
async function fun2(){
return new Promise((resolve, reject)=>{
setTimeout(()=>{
resolve('Promise func2')
}, 1000)
}
)
}
async function update(){
console.log("update");
}
// 游戏引擎先调用start,再调用update
async function main(){
await start();
await update();
}
main();
由于start和update本身不是async修饰,因此没办法控制async的方法和update的执行顺序。
最终结论是:通过拖拽prefab的方式去执行,或者UI和数据分离的方式执行。
边栏推荐
- AI目标分割能力,无需绿幕即可实现快速视频抠图
- 拼多多借力消博会推动国内农产品品牌升级 看齐国际精品农货
- 考完PMP学什么?前方软考等着你~
- ALCCIKERS Shane 20191114
- How to adjust the cross cursor too small, CAD dream drawing calculation skills
- LeetCode brushing diary: 33. Search and rotate sorted array
- Golang分布式应用之Redis
- leetcode / anagram in string - some permutation of s1 string is a substring of s2
- 垃圾回收器CMS和G1
- [LeetCode Daily Question]——654. The largest binary tree
猜你喜欢
nacos启动报错,已配置数据库,单机启动
FOFAHUB使用测试
BioVendor人俱乐部细胞蛋白(CC16)Elisa试剂盒研究领域
"NetEase Internship" Weekly Diary (3)
Win Go development kit installation configuration, GoLand configuration
ofstream,ifstream,fstream read and write files
Talking about the "horizontal, vertical and vertical" development trend of domestic ERP
The principle and code implementation of intelligent follower robot in the actual combat of innovative projects
『网易实习』周记(一)
Nanoprobes纳米探针丨Nanogold偶联物的特点和应用
随机推荐
AOF rewrite
libcurl访问url保存为文件的简单示例
Remember a gorm transaction and debug to solve mysql deadlock
leetcode / anagram in string - some permutation of s1 string is a substring of s2
永磁同步电机36问(三)——SVPWM代码实现
Personal blog system project test
Nanoprobes免疫测定丨FluoroNanogold试剂免疫染色方案
LeetCode brushing diary: 53, the largest sub-array and
软件测试 接口自动化测试 pytest框架封装 requests库 封装统一请求和多个基础路径处理 接口关联封装 测试用例写在yaml文件中 数据热加载(动态参数) 断言
记一次gorm事务及调试解决mysql死锁
永磁同步电机36问(二)——机械量与电物理量如何转化?
Win Go development kit installation configuration, GoLand configuration
Remember a pit for gorm initialization
ALCCIKERS Shane 20191114
数据链路层的数据传输
Speed up your programs with bitwise operations
NIO's Sword
Scheduled tasks for distributed applications in Golang
Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021: Interpretation
Redis 底层的数据结构