ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` 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([])将会永远挂起。