当前位置:网站首页>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和数据分离的方式执行。
边栏推荐
- MySQL8 download, start, configure, verify
- Analysis of the status quo of digital transformation of manufacturing enterprises
- BioVendor人俱乐部细胞蛋白(CC16)Elisa试剂盒研究领域
- 【Unity入门计划】2D Game Kit:初步了解2D游戏组成
- to-be-read list
- Garbage Collector CMS and G1
- 2022-08-01 mysql/stoonedb slow SQL-Q18 analysis
- 优炫数据库导库导错了能恢复吗?
- The underlying data structure of Redis
- 2022河南青训联赛第(三)场
猜你喜欢

AOF重写

Nanoprobes多组氨酸 (His-) 标签标记:重组蛋白检测方案

Electronic Manufacturing Warehouse Barcode Management System Solution

垃圾回收器CMS和G1

Remember a pit for gorm initialization

Redis 底层的数据结构

Redis Subscription and Redis Stream

2022河南青训联赛第(三)场

记一次gorm事务及调试解决mysql死锁

软件测试 接口自动化测试 pytest框架封装 requests库 封装统一请求和多个基础路径处理 接口关联封装 测试用例写在yaml文件中 数据热加载(动态参数) 断言
随机推荐
MySQL optimization strategy
A good book for newcomers to the workplace
The underlying data structure of Redis
项目后台技术Express
AOF重写
Entry name 'org/apache/commons/codec/language/bm/gen_approx_greeklatin.txt' collided
2023年起,这些地区软考成绩低于45分也能拿证
用位运算为你的程序加速
Hash collisions and consistent hashing
Data transfer at the data link layer
[LeetCode Daily Question] - 103. Zigzag Level Order Traversal of Binary Tree
BI-SQL丨WHILE
libcurl访问url保存为文件的简单示例
LeetCode brush diary: LCP 03. Machine's adventure
考完PMP学什么?前方软考等着你~
oracle query scan full table and walk index
"NetEase Internship" Weekly Diary (1)
C语言之插入字符简单练习
Pinduoduo leverages the consumer expo to promote the upgrading of domestic agricultural products brands and keep pace with international high-quality agricultural products
60 Feature Engineering Operations: Using Custom Aggregate Functions【Favorites】