当前位置:网站首页>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
})
边栏推荐
- leetcode 72. Edit distance edit distance (medium)
- 【室友用一局王者荣耀的时间学会了用BI报表数据处理】
- 图片懒加载的原理
- Sword finger offer 65 Add without adding, subtracting, multiplying, dividing
- Taobao commodity review API interface (item_review get Taobao commodity review API interface), tmall commodity review API interface
- MYSQL架构——用户权限与管理
- [the 2023 autumn recruitment of MIHA tour] open [the only exclusive internal push code of school recruitment eytuc]
- Redis的持久化机制
- NFT Insider #64:电商巨头eBay提交NFT相关商标申请,毕马威将在Web3和元宇宙中投入3000万美元
- 攻防世界 MISC 进阶区 Ditf
猜你喜欢

vim编辑器知识总结

The Sandbox 和数字好莱坞达成合作,通过人力资源开发加速创作者经济的发展

Lost in the lock world of MySQL

Redis入门完整教程:列表讲解

Attack and defense world misc master advanced zone 001 normal_ png

Set up a website with a sense of ceremony, and post it to 1/2 of the public network through the intranet

业务太忙,真的是没时间搞自动化理由吗?

Breakpoint debugging under vs2019 c release

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

sobel过滤器
随机推荐
集群的概述与定义,一看就会
蓝队攻防演练中的三段作战
剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
leetcode 72. Edit distance edit distance (medium)
SPSS安装激活教程(包含网盘链接)
啃下大骨头——排序(二)
Redis入门完整教程:键管理
Advanced area a of attack and defense world misc Masters_ good_ idea
Redis入门完整教程:初识Redis
Logo special training camp section III initial creative techniques
Serial port data frame
[machine learning] handwritten digit recognition
环境加密技术解析
繁华落尽、物是人非:个人站长该何去何从
质量体系建设之路的分分合合
10 schemes to ensure interface data security
Analog rocker controlled steering gear
Erik baleog and Olaf, advanced area of misc in the attack and defense world
Redis入门完整教程:Redis使用场景
[cooking record] - stir fried 1000 pieces of green pepper