当前位置:网站首页>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和数据分离的方式执行。
边栏推荐
- Redis for distributed applications in Golang
- 2022年NPDP考完多久出成绩?怎么查询?
- Project Background Technology Express
- From 2023 onwards, these regions will be able to obtain a certificate with a score lower than 45 in the soft examination.
- [LeetCode Daily Question]——654. The largest binary tree
- Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021:解读
- 2022-08-01 Install mysql monitoring tool phhMyAdmin
- Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021: Interpretation
- 2022-08-01 Reflection
- Simple example of libcurl accessing url saved as file
猜你喜欢

Chopper webshell feature analysis

软件测试 接口自动化测试 pytest框架封装 requests库 封装统一请求和多个基础路径处理 接口关联封装 测试用例写在yaml文件中 数据热加载(动态参数) 断言

LeetCode Brushing Diary: 74. Searching 2D Matrix

Electronic Manufacturing Warehouse Barcode Management System Solution

2022-08-01 mysql/stoonedb慢SQL-Q18分析

BioVendor Human Club Cellular Protein (CC16) Elisa Kit Research Fields

volatile原理解析

The state status is displayed incorrectly after the openGauss switch

BI-SQL丨WHILE

Oracle19c安装图文教程
随机推荐
哈希冲突和一致性哈希
手写一个博客平台~第一天
C语言之插入字符简单练习
【 wheeled odometer 】
AntPathMatcher uses
垃圾回收器CMS和G1
Chengdu openGauss user group recruit!
『网易实习』周记(三)
个人博客系统项目测试
Redis Subscription and Redis Stream
Redis for distributed applications in Golang
[ORB_SLAM2] SetPose, UpdatePoseMatrices
messy website
2022-08-01 mysql/stoonedb slow SQL-Q18 analysis
ofstream,ifstream,fstream read and write files
Hiring a WordPress Developer: 4 Practical Ways
The underlying data structure of Redis
【LeetCode每日一题】——654.最大二叉树
The failure to create a role in Dahua Westward Journey has been solved
【LeetCode每日一题】——103.二叉树的锯齿形层序遍历