如何在nodejs中保持一个接一个的发送请求

时间:2020-11-10 17:12:36

标签: node.js server backend puppeteer

我正在使用puppeteer来自动化网站,puppeteer会话可能需要大约30到60秒,并且我想在该请求完成之前立即发出一个请求(打开另一个puppeteer会话),我意识到我可以不要使用setInterval,因为在我的情况下时间不是恒定的,我该如何实现

1 个答案:

答案 0 :(得分:0)

使用递归函数在完成后立即调用同一函数。

async function bot(){
  const browser = await puppeteer.launch()
  // other code
  await browser.close()
}

async function fireMyRequest(){
  await bot()
  await fireMyRequest()
}