当前位置:网站首页>js promise.all
js promise.all
2022-07-02 06:41:00 【大鸡腿最好吃】
let d= promise.all([a,b,c])
接受一个promise数组,只有数组里面的promise全部成功才返回成功,要不就失败
只有a、b、c的状态都变成fulfilled,d的状态才会变成fulfilled,此时a、b、c的返回值组成一个数组,传递给d的回调函数。
只要a、b、c之中有一个被rejected,d的状态就变成rejected,此时第一个被reject的实例的返回值,会传递给p的回调函数。
面试题
函数c在函数a和b执行完后才执行
就使用promise.all
let a=function(){
console.log('a')
}
let b=function(){
console.log('b')
}
let p1 = new Promise((resolve, reject) => {
a()
resolve('成功了')
})
let p2 = new Promise((resolve, reject) => {
b()
resolve('success')
})
let c=function(){
console.log('c')
}
Promise.all([p1, p2]).then((result) => {
c()
})
边栏推荐
- Project practice, redis cluster technology learning (12)
- Solutions to a series of problems in sqoop job creation
- 2.14 is it Valentine's day or Valentine's day when the mainstream market continues to fluctuate and wait for changes?
- 网络通信学习
- What is the relationship between realizing page watermarking and mutationobserver?
- Project practice, redis cluster technology learning (16)
- Remember the use of add method once
- Understand the composition of building energy-saving system
- 合并有序数列
- Project practice, redis cluster technology learning (13)
猜你喜欢

SAP Spartacus express checkout design

Network real-time video streaming based on OpenCV

stm32和电机开发(上位系统)

Delivery mode design of Spartacus UI of SAP e-commerce cloud

Postman--使用

01安装虚拟机

Webui automated learning

Solutions to a series of problems in sqoop job creation

Notes de base sur les plans illusoires d'IA (triés en 10 000 mots)

两数之和,求目标值
随机推荐
Basic usage of mock server
Operator exercises
2021-10-02
Blender model import UE, collision settings
【避坑指南】Unity3D项目接入腾讯Bugly工具时遇到的坑
[unity3d] nested use layout group to make scroll view with dynamic sub object height
What is call / cc- What is call/cc?
STM32 and motor development (upper system)
Blender camera surround motion, animation rendering, video synthesis
[visual studio] every time you open a script of unity3d, a new vs2017 will be automatically reopened
Postman -- use
Understand the composition of building energy-saving system
Pytest framework implements pre post
Remember the use of add method once
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
[unity3d] cannot correctly obtain the attribute value of recttransform, resulting in calculation error
Deep understanding of redis cache avalanche / cache breakdown / cache penetration
【Unity3D】无法正确获取RectTransform的属性值导致计算出错
Flink submitter
判断数组中是否存在重复元素