You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionPromiseRace(promiseArr){returnnewPromise((resolve,reject)=>{if(!Array.isArray(promiseArr)){returnreject(newError("Input must be an array"));}for(leti=0;i<promiseArr.length;i++){Promise.resolve(promiseArr[i]).then(resolve).catch(reject);}});}constp1=newPromise((res,rej)=>setTimeout(res,1000,"p1"));constp2=newPromise((res,rej)=>setTimeout(res,500,"p2"));constp3=newPromise((res,rej)=>setTimeout(res,1500,"p3"));PromiseRace([p1,p2,p3]).then(console.log).catch(console.error);
functionPromiseAny(promiseArr){returnnewPromise((resolve,reject)=>{if(!Array.isArray(promiseArr)){returnreject(newError("Input must be an array"));}leterrors=[];letcount=0;for(leti=0;i<promiseArr.length;i++){Promise.resolve(promiseArr[i]).then(resolve).catch((error)=>{errors.push(error);count++;if(count===promiseArr.length){reject(newAggregateError(errors,'All promises failed'));}});}});}constp1=newPromise((res,rej)=>setTimeout(rej,1000,"p1 error"));constp2=newPromise((res,rej)=>setTimeout(res,500,"p2"));constp3=newPromise((res,rej)=>setTimeout(rej,1500,"p3 error"));PromiseAny([p1,p2,p3]).then(console.log).catch(console.error);
简介二者区别,以及使用场景
The text was updated successfully, but these errors were encountered: