当前位置:网站首页>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
})
边栏推荐
- Locust performance test - environment construction and use
- Install the gold warehouse database of NPC
- Three stage operations in the attack and defense drill of the blue team
- Google Earth Engine(GEE)——以MODIS/006/MCD19A2为例批量下载逐天AOD数据逐天的均值、最大值、最小值、标准差、方差统计分析和CSV下载(北京市各区为例)
- 【OpenGL】笔记二十九、抗锯齿(MSAA)
- Wake up day, how do I step by step towards the road of software testing
- 图片懒加载的原理
- Google Earth engine (GEE) - globfire daily fire data set based on mcd64a1
- LOGO特训营 第四节 字体设计的重要性
- 环境加密技术解析
猜你喜欢

Redis入门完整教程:客户端通信协议

Redis入门完整教程:发布订阅

Logo special training camp Section IV importance of font design

Attack and defense world misc advanced grace-50

Redis introduction complete tutorial: slow query analysis

攻防世界 MISC 进阶区 3-11

Naacl-22 | introduce the setting of migration learning on the prompt based text generation task

Attack and Defense World MISC Advanced Area Erik baleog and Olaf

Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf

Locust performance test - environment construction and use
随机推荐
About stack area, heap area, global area, text constant area and program code area
Hit the core in the advanced area of misc in the attack and defense world
Redis入门完整教程:慢查询分析
Analysis of environmental encryption technology
模拟摇杆控制舵机
[roommate learned to use Bi report data processing in the time of King glory in one game]
Duplicate ADMAS part name
Breakpoint debugging under vs2019 c release
Attack and Defense World MISC Advanced Area Erik baleog and Olaf
都说软件测试很简单有手就行,但为何仍有这么多劝退的?
The overview and definition of clusters can be seen at a glance
9 - 类
leetcode 72. Edit distance edit distance (medium)
Redis入门完整教程:Pipeline
攻防世界 MISC 进阶区 Erik-Baleog-and-Olaf
MD5 tool class
A complete tutorial for getting started with redis: Pipeline
Create Ca and issue certificate through go language
Redis入门完整教程:发布订阅
攻防世界 MISC 高手进阶区 001 normal_png