🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
``` var p1 = Promise.resolve(42); var p2 = new Promise((resolve, reject) => setTimeout(() => resolve(43), 100)); var v3 = 44; var p4 = new Promise((resolve, reject) => setTimeout(() => reject('oops'), 10)); //有一个被拒绝则整体被拒绝 Promise.all([p1, p2, v3]).then(data => console.log(data)); //[42, 43, 44] Promise.all([p1, p2, v3, p4]) .then(data => console.log(data), err => console.log(err)); //oops Promise.race([p2, p1, v3]).then(data => console.log(data)); //42 Promise.race([p2, p4]) .then(data => console.log(data), err => console.log(err)); //oops ``` Promise.all([])将会立即完成(没有完成值),Promise.race([])将会永远挂起。