Open rrr523 opened 4 years ago
1.可设置一个请求数量Q,在mian中进行尾递归接收消息,每当一个请求完成时http_post向main发送消息告知其请求完成,Q-1,直至Q为0时main结束。 2.对于上万个id,可以通过创建一个gen_server来代理这些POST请求,所有POST请求通过gen_server来发起请求,当gen_server收到POST请求消息时,为该请求spawn一个进程,当POST请求完成时类似第1点中向main发送完成消息以更新请求进度。
以上为本人拙见
@wu4517519 首先谢谢您的回复
我只是想创建一个类似线程池的东西,erlang 中似乎没有这个概念。
只所以需要这个『线程池』,是因为这是个类似爬虫的程序,希望能够控制访问的量,比如我创建 100 个 actor去处理几十万个 id 这种情况。
你说的用 gen_server 来代理,似乎是直接一下子就处理几十万 id 了。
本人初学 Erlang,对 actor 模型刚刚了解,写了一段代码,做爬虫使用:
现在的问题是,我执行以后立刻就执行到
start()
的done
了,主进程立马结束:我有两个问题:
请指教 😢