async/await简单使用
程序员文章站
2022-05-04 12:38:08
function process(i) { var p = new Promise(function(resolve,reject){ setTimeout(function(){ console.log(i); resolve(i); },i*1000); }); return p; } asyn... ......
function process(i) { var p = new promise(function(resolve,reject){ settimeout(function(){ console.log(i); resolve(i); },i*1000); }); return p; } async function call(){ let res1=await process(6); let res2=await process(3); let res3=await process(4); let res4=await process(9); let res5=await process(1); return res1+res2+res3+res4+res5; } call()
//结果:依次间隔6,3,4,9,1秒,输出字符6,3,4,9,1。
推荐阅读