当前位置:网站首页>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
})
边栏推荐
- Attack and defense world misc master advanced zone 001 normal_ png
- 10 schemes to ensure interface data security
- Redis入门完整教程:HyperLogLog
- Serial port data frame
- Google Earth engine (GEE) - tasks upgrade enables run all to download all images in task types with one click
- 环境加密技术解析
- Unity Xiuxian mobile game | Lua dynamic sliding function (specific implementation of three source codes)
- 集群的概述与定义,一看就会
- Solana chain application crema was shut down due to hacker attacks
- 剑指 Offer 67. 把字符串转换成整数
猜你喜欢
![[machine learning] handwritten digit recognition](/img/26/cabdc5c92035181d82f6f809e6df0f.png)
[machine learning] handwritten digit recognition

Attack and defense world misc advanced area Hong

Logo Camp d'entraînement section 3 techniques créatives initiales

LOGO特训营 第四节 字体设计的重要性

攻防世界 misc 进阶区 2017_Dating_in_Singapore

【OpenGL】笔记二十九、抗锯齿(MSAA)

Unity修仙手游 | lua动态滑动功能(3种源码具体实现)

LOGO特训营 第二节 文字与图形的搭配关系

Google Earth Engine(GEE)——基于 MCD64A1 的 GlobFire 日常火灾数据集

Redis入门完整教程:集合详解
随机推荐
SPSS安装激活教程(包含网盘链接)
The Sandbox 和数字好莱坞达成合作,通过人力资源开发加速创作者经济的发展
测试必会:BUG的分类及推进解决
[OpenGL] note 29 anti aliasing (MSAA)
攻防世界 MISC 进阶区 hong
Redis入门完整教程:Bitmaps
Record: how to scroll screenshots of web pages on Microsoft edge in win10 system?
Google Earth Engine(GEE)——以MODIS/006/MCD19A2为例批量下载逐天AOD数据逐天的均值、最大值、最小值、标准差、方差统计分析和CSV下载(北京市各区为例)
md5工具类
MD5 tool class
Unity Xiuxian mobile game | Lua dynamic sliding function (specific implementation of three source codes)
Analog rocker controlled steering gear
Unity修仙手游 | lua动态滑动功能(3种源码具体实现)
该如何去选择证券公司,手机上开户安不安全
Analysis of the self increasing and self decreasing of C language function parameters
记录:关于Win10系统中Microsoft Edge上的网页如何滚动截屏?
Feature scaling normalization
模拟摇杆控制舵机
Attack and defense world misc advanced grace-50
Redis入门完整教程:初识Redis