当前位置:网站首页>Async await used in map
Async await used in map
2022-07-04 22:55:00 【Chirp bit】
Preface
When practicing wechat applet , You need to traverse the elements in the array , Get the id And send a request to request the corresponding resource . This requires that map Loop traversal and async await Combine . Because of asynchronous operation ,async The function returns a promise object , be map Traversal returns a promise An array of objects , We need to wait until we get all promise After that, follow-up operations .
Promise.all
Promise.all Multiple Promise The example is packaged into a new Promise example . meanwhile , Success and failure return values are different , Success returns an array of results , And when they fail, they return to be the first reject Value of failure state .
And map combination
The general pattern of asynchrony map yes Promise.all(arr.map(async (...) => ...))
.
example ( Application of wechat applet )
let videos = video.datas.map(async item =>{
item.id = index++;
item.videoUrl = await this.getVideoUrl(item.data.vid)
return item
})
let temp = await Promise.all(videos)
this.setData({
video:temp
})
边栏推荐
- String类中的常用方法
- 剑指 Offer 67. 把字符串转换成整数
- Introducing QA into the software development lifecycle is the best practice that engineers should follow
- Redis入门完整教程:Redis使用场景
- 【剑指Offer】6-10题
- 都说软件测试很简单有手就行,但为何仍有这么多劝退的?
- Set up a website with a sense of ceremony, and post it to 1/2 of the public network through the intranet
- Google Earth Engine(GEE)——基于 MCD64A1 的 GlobFire 日常火灾数据集
- Redis introduction complete tutorial: slow query analysis
- The overview and definition of clusters can be seen at a glance
猜你喜欢
Logo special training camp Section V font structure and common design techniques
Attack and defense world misc advanced area ditf
攻防世界 misc 进阶区 2017_Dating_in_Singapore
攻防世界 MISC 进阶 glance-50
The new version judges the code of PC and mobile terminal, the mobile terminal jumps to the mobile terminal, and the PC jumps to the latest valid code of PC terminal
Redis入门完整教程:发布订阅
[the 2023 autumn recruitment of MIHA tour] open [the only exclusive internal push code of school recruitment eytuc]
Breakpoint debugging under vs2019 c release
Set up a website with a sense of ceremony, and post it to 1/2 of the public network through the intranet
Redis入门完整教程:集合详解
随机推荐
【室友用一局王者荣耀的时间学会了用BI报表数据处理】
Sword finger offer 68 - ii The nearest common ancestor of binary tree
共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf
Why is Dameng data called the "first share" of domestic databases?
Redis入门完整教程:键管理
攻防世界 MISC 进阶区 Erik-Baleog-and-Olaf
MD5 tool class
Duplicate ADMAS part name
Redis入门完整教程:慢查询分析
Google Earth engine (GEE) - tasks upgrade enables run all to download all images in task types with one click
[OpenGL] note 29 anti aliasing (MSAA)
Redis入门完整教程:事务与Lua
Summary of index operations in mongodb
[cooking record] - stir fried 1000 pieces of green pepper
Microservices -- Opening
MYSQL架构——逻辑架构
[machine learning] handwritten digit recognition
攻防世界 MISC 进阶区 3-11
剑指 Offer 65. 不用加减乘除做加法
The Sandbox 和数字好莱坞达成合作,通过人力资源开发加速创作者经济的发展