当前位置:网站首页>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()
})
边栏推荐
猜你喜欢

Feature (5): how to organize information

2.14 is it Valentine's day or Valentine's day when the mainstream market continues to fluctuate and wait for changes?

快速做出原型

Postman--使用

2021-10-04

MPLS experiment

【虚幻4】从U3D到UE4的转型之路

Aiphacode is not a substitute for programmers, but a tool for developers

Flink calculates topn hot list in real time

Pytest framework implements pre post
随机推荐
STM32 and motor development (upper system)
Flink calculates topn hot list in real time
Post disaster reconstruction -- Floyd thought
虚幻材质编辑器基础——如何连接一个最基本的材质
Project practice, redis cluster technology learning (13)
Project practice, redis cluster technology learning (VIII)
[Fantasy 4] introduction and use of UMG components (under update...)
stm32和电机开发(上位系统)
Mock Server基本使用方法
Importing tables from sqoop
Message mechanism -- getting to know messages and message queues for the first time
flume 190 INSTALL
Stm32 et développement de moteurs (système supérieur)
Ctrip starts mixed office. How can small and medium-sized enterprises achieve mixed office?
This article takes you to learn in detail what is fiber to home FTTH
[visual studio] every time you open a script of unity3d, a new vs2017 will be automatically reopened
【避坑指南】使用UGUI遇到的坑:Text组件无法首行缩进两格
Metaclass type and using metaclass to implement model class ORM
2021-09-12
Rapid prototyping