当前位置:网站首页>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和数据分离的方式执行。
边栏推荐
- nacos启动报错,已配置数据库,单机启动
- AOF重写
- Scheduled tasks for distributed applications in Golang
- PHP uses PHPRedis and Predis
- FOFAHUB使用测试
- AI target segmentation capability for fast video cutout without green screen
- Personal blog system project test
- Safety (2)
- swift项目,sqlcipher3 -> 4,无法打开旧版数据库有办法解决吗
- ALCCIKERS Shane 20191114
猜你喜欢

The Paddle Open Source Community Quarterly Report is here, everything you want to know is here

『网易实习』周记(二)

LeetCode刷题日记:LCP 03.机器人大冒险

The underlying data structure of Redis

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

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

A good book for newcomers to the workplace

Entry name 'org/apache/commons/codec/language/bm/gen_approx_greeklatin.txt' collided

Hash collisions and consistent hashing

Handwritten Blog Platform ~ Day Two
随机推荐
Redis for distributed applications in Golang
The state status is displayed incorrectly after the openGauss switch
2022-08-01 mysql/stoonedb慢SQL-Q18分析
Simple example of libcurl accessing url saved as file
永磁同步电机36问(二)——机械量与电物理量如何转化?
BioVendor Human Club Cellular Protein (CC16) Elisa Kit Research Fields
LeetCode brush diary: LCP 03. Machine's adventure
【Unity入门计划】2D Game Kit:初步了解2D游戏组成
手写博客平台~第二天
2022 Henan Youth Training League Game (3)
『网易实习』周记(二)
AI目标分割能力,无需绿幕即可实现快速视频抠图
Electronic Manufacturing Warehouse Barcode Management System Solution
Reflex WMS Intermediate Series 7: What should I do if I want to cancel the picking of an HD that has finished picking but has not yet been loaded?
From 2023 onwards, these regions will be able to obtain a certificate with a score lower than 45 in the soft examination.
openGauss切换后state状态显示不对
NIO‘s Sword(牛客多校赛)
oracle查询扫描全表和走索引
永磁同步电机36问(三)——SVPWM代码实现
记一次gorm事务及调试解决mysql死锁