async await循环请求

var sleep = function (item,time) {
  return new Promise(function (resolve, reject) {
    setTimeout(function () {
        console.log(item)
          resolve('1');
    }, time);
  })
};

async function fot () {
  //foreach无法写出来 只能用for了
for (let i=0;i<arr.length;i++){
        await sleep(arr[i],2000);
    }
    console.log(1111111)
}
fot()    

猜你喜欢

转载自www.cnblogs.com/dabiaogea/p/10348404.html
今日推荐