javascript - 为什么我的递归函数不会被 promise 调用?
问题描述
无论我做什么,我都无法让我的函数被递归调用。我试过返回并存储到一个变量和许多其他东西中,但它只被调用一次?
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();
我以为final.then()
就意味着promise已经完成并且已经成功了?
更新:
似乎删除.end()
已经解决了我的问题。我不完全理解噩梦文档为https://github.com/segmentio/nightmare,它说它完成了任何队列操作。我从一个例子中提取了一些代码,它就end()
在那里。我会因为删除它而受到任何影响吗?
解决方案
你可以试试这个流程,
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();
推荐阅读
- glsl - 根据 glslangValidator.exe 不支持 GL_ARB_gpu_shader_fp64,但我实际上支持?
- r - chromoPlot 错误 - 读取的数据多于文件中的数据
- r - 如何使用 R 创建滞后
- node.js - 如何使用 knex 查询 PostGresSQl 检查逗号分隔字段中的单个值
- html - 如何在 Messenger Chat 中添加图片?
- json - 如何从 XSD 创建 BQ 模式
- amazon-redshift - 根据架构列出所有表列的最小值和最大值
- arrays - 如何使用angularjs在html表中打印数组的特定元素?
- ruby-on-rails - 无法安装 RMagick 2.16.0。找不到 MagickWand.h
- server - 使用查询获取从 HTTP 重定向到 HTTPS 无法正常工作