流浪のwolf

卷帝

导航

Promise.all、race和any方法都是什么意思?

// // 执行多个并行任务
const promiseAll = [
    thenFs.readFile('./files/1.txt','utf8'),
    thenFs.readFile('./files/2.txt','utf8'),
    thenFs.readFile('./files/3.txt','utf8'),
]

 

Primse.all 等待机制,等到所有的任务执行完毕,才会执行then函数 ;

Promise.race赛跑机制,等到第一个执行完毕就会执行then函数 ;

Promise.any只要有一个任务被执行,就会执行then函数  ;

posted on 2022-11-15 14:03  流浪のwolf  阅读(35)  评论(0编辑  收藏  举报