当前位置:网站首页>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和数据分离的方式执行。
边栏推荐
- libcurl访问url保存为文件的简单示例
- 密码学的基础:X.690和对应的BER CER DER编码
- Moonbeam and Project integration of the Galaxy, bring brand-new user experience for the community
- 哈希冲突和一致性哈希
- 【LeetCode每日一题】——103.二叉树的锯齿形层序遍历
- FOFAHUB使用测试
- From 2023 onwards, these regions will be able to obtain a certificate with a score lower than 45 in the soft examination.
- 【LeetCode每日一题】——704.二分查找
- Redis 底层的数据结构
- LeetCode Review Diary: 153. Find the Minimum Value in a Rotated Sort Array
猜你喜欢

Redis Subscription and Redis Stream

nacos startup error, the database has been configured, stand-alone startup

Nanoprobes丨1-巯基-(三甘醇)甲醚功能化金纳米颗粒

Golang分布式应用之定时任务

BI-SQL丨WHILE

Ringtone 1161. Maximum In-Layer Elements and

AI目标分割能力,无需绿幕即可实现快速视频抠图

oracle query scan full table and walk index

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

Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021:解读
随机推荐
A good book for newcomers to the workplace
Software testing Interface automation testing Pytest framework encapsulates requests library Encapsulates unified request and multiple base path processing Interface association encapsulation Test cas
Win Go development kit installation configuration, GoLand configuration
The state status is displayed incorrectly after the openGauss switch
Simple example of libcurl accessing url saved as file
LeetCode刷题日记:LCP 03.机器人大冒险
CodeTon Round 2 D. Magical Array 规律
TKU remembers a single-point QPS optimization (I wish ITEYE is finally back)
【ORB_SLAM2】void Frame::AssignFeaturesToGrid()
Redis Persistence - RDB and AOF
Power button 1374. Generate each character string is an odd number
"NetEase Internship" Weekly Diary (3)
Service discovery of kubernetes
MySQL8 download, start, configure, verify
Chengdu openGauss user group recruit!
考完PMP学什么?前方软考等着你~
libcurl访问url保存为文件的简单示例
使用DBeaver进行mysql数据备份与恢复
PHP uses PHPRedis and Predis
Centos7 安装postgresql并开启远程访问