当前位置:网站首页>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和数据分离的方式执行。
边栏推荐
- 『网易实习』周记(二)
- volatile原理解析
- "NetEase Internship" Weekly Diary (3)
- TKU remembers a single-point QPS optimization (I wish ITEYE is finally back)
- Coding Experience Talk
- 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?
- LeetCode 213. Robbery II (2022.08.01)
- BI-SQL丨WHILE
- A good book for newcomers to the workplace
- AWR分析报告问题求助:SQL如何可以从哪几个方面优化?
猜你喜欢
Constructor instance method inheritance of typescript37-class (extends)
Chopper webshell feature analysis
Pinduoduo leverages the consumer expo to promote the upgrading of domestic agricultural products brands and keep pace with international high-quality agricultural products
『网易实习』周记(一)
密码学的基础:X.690和对应的BER CER DER编码
"NetEase Internship" Weekly Diary (3)
Talking about the "horizontal, vertical and vertical" development trend of domestic ERP
手写博客平台~第二天
2022 Henan Youth Training League Game (3)
Analysis of the status quo of digital transformation of manufacturing enterprises
随机推荐
[LeetCode Daily Question]——654. The largest binary tree
to-be-read list
Effects of Scraping and Aggregation
Moonbeam and Project integration of the Galaxy, bring brand-new user experience for the community
【 wheeled odometer 】
From 2023 onwards, these regions will be able to obtain a certificate with a score lower than 45 in the soft examination.
数据链路层的数据传输
拼多多借力消博会推动国内农产品品牌升级 看齐国际精品农货
2022-07-30 mysql8 executes slow SQL-Q17 analysis
Nanoprobes免疫测定丨FluoroNanogold试剂免疫染色方案
MySQL optimization strategy
BioVendor人俱乐部细胞蛋白(CC16)Elisa试剂盒研究领域
The failure to create a role in Dahua Westward Journey has been solved
Hash collisions and consistent hashing
AOF rewrite
nacos启动报错,已配置数据库,单机启动
记一个gorm初始化的坑
The first time I wrote a programming interview question for Niu Ke: input a string and return the letter with the most occurrences of the string
Ask God to answer, how should this kind of sql be written?
LeetCode brushing diary: 33. Search and rotate sorted array