代码之家  ›  专栏  ›  技术社区  ›  Taylor A. Leach

为什么我的递归函数不会被promise调用?

  •  0
  • Taylor A. Leach  · 技术社区  · 8 年前

    无论我做什么,我都不能让我的函数被递归调用。我试过返回并存储到一个变量和许多其他东西,但它只被调用过一次?

     var scrape = () => {
        var waitTime = randomIntFromInterval(1000, 10000);
    
        nightmare.goto('http://...') 
          .wait(waitTime)
          .evaluate(() => {
            var data = [];
            // ... doing work to get data from browser here
            return data
          })
          .end()
          .then((result) => {
            console.log('scraped successfully!' + new Date());
            scrape();
          }
        )
      }
    
      scrape();
    

    我以为决赛 .then() 意味着承诺已经完成并且成功了?

    更新:

    好像要搬走了 .end() 解决了我的问题。我不完全理解噩梦医生的意思 https://github.com/segmentio/nightmare end() 在那里。去掉这个会有什么影响吗?

    2 回复  |  直到 8 年前
        1
  •  0
  •   Rohith Murali    8 年前

    你能试试这个流程吗,

    var scrape = () => {
    var waitTime = randomIntFromInterval(1000, 10000);
    
    nightmare.goto('http://...') 
    
      .then((result) => {
        console.log('scraped successfully!' + new Date());
    
        ////do the end process here////
    
        scrape();
      }
      )
     }
    
     scrape();
    
        2
  •  0
  •   Aaronius    8 年前

    将psuedo随机散列附加到URL的末尾,如 #' + new Date().getTime() . 如果这对你有用,那么你可能会遇到 this issue 噩梦在哪里 .goTo()