var sleep = (time)=> { return new Promise( (resolve, reject)=> { setTimeout(() =>{ let flag=0 if(flag==1){ resolve(); }else{ reject() } }, time); }) }; var start = async () =>{ // 在這裏使用起來就像同步代碼那樣直觀 try { console.log('start'); await sleep(5000); console.log("5s") await sleep(3000) console.log('3s') console.log('end'); }catch(e) { console.error("這是回掉錯誤") } }; start();