ES9中Promise是如何“兜底”操作的?
function Gen(time){ return new Promise((resolve,reject)=>{ setTimeout(function(){ if(time<500){ reject(time); }else{ resolve(time); } },time) }) } Gen(Math.random()*1000) .then(val=>console.log('resolve',val)) .catch(err=>console.log('reject',err)) .finally(()=>{console.log('finish')})//关闭数据库,保证数据库是断开的 //resolve 564.8225885780598 //finish //多刷几次,输出会变 //reject 94.27830818104587 //finish