当前位置:网站首页>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()
})
边栏推荐
- 判断数组中是否存在重复元素
- This article takes you to learn in detail what is fiber to home FTTH
- Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
- Sum the two numbers to find the target value
- sqoop创建job出现的一系列问题解决方法
- Project practice, redis cluster technology learning (VII)
- MySQL -- time zone / connector / driver type
- 【MySQL】连接MySQL时出现异常:Connection must be valid and open
- 01-spooldir
- Considerations for Apache deploying static web page projects
猜你喜欢
Ctrip starts mixed office. How can small and medium-sized enterprises achieve mixed office?
虛幻AI藍圖基礎筆記(萬字整理)
Flink calculates topn hot list in real time
Flink实时计算topN热榜
Application of rxjs operator withlatestfrom in Spartacus UI of SAP e-commerce cloud
Following nym, the new project Galaxy token announced by coinlist is gal
VLAN experiment
Network real-time video streaming based on OpenCV
allure--常用配置项
[unreal] key to open the door blueprint notes
随机推荐
What is the relationship between realizing page watermarking and mutationobserver?
Configuration programmée du générateur de plantes du moteur illusoire UE - - Comment générer rapidement une grande forêt
2.14 is it Valentine's day or Valentine's day when the mainstream market continues to fluctuate and wait for changes?
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
Ue5 - AI pursuit (blueprint, behavior tree)
高考的意义是什么
Project practice, redis cluster technology learning (12)
【Unity3D】无法正确获取RectTransform的属性值导致计算出错
Vscode auto format
Basic usage of mock server
flume 190 INSTALL
Flink实时计算topN热榜
flink 提交程序
VLAN experiment
Pytest-- test report allure configuration
Understand the composition of building energy-saving system
Database -- acid of transaction -- introduction / explanation
Post disaster reconstruction -- Floyd thought
02-taildir source
MySQL -- time zone / connector / driver type