async/await简单使用
程序员文章站
2022-12-21 19:53: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。
上一篇: 怎样使用两行代码实现博客园打赏功能
下一篇: vmware上安装centos7虚拟机
推荐阅读