Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在我的应用程序中使用 Apify SDK,并使用 Apify.main() 函数编写了许多爬虫。main() 的最后一个动作是退出节点进程,但这不符合我的目的。有没有办法克服这种行为?
您不需要使用Apify.main,或者您可以简单地继续使用它之后的代码。Apify.main不退出进程。以下代码完全运行:
Apify.main
const Apify = require('apify'); Apify.main(async () => { console.log('main'); }); console.log('after main');
Apify.main 的主要原因是:
1) 确保其中的函数提前完成,这样它就不会像顶级代码那样等待回调。
2)它发出一些事件。