在 Twitter 的Finagle
,map
和flatMap
可用于链接多个异步操作。例如,一个简单的网络爬虫可能会做类似的事情,
downloadURL(url) // download a web page
.flatMap(extractProducts) // extract individual products for sale on it
.foreach(saveToDatabase) // save output to a database
我想gevent
在 Python 中做一些非常相似的事情,但我不知道该怎么做。Greenlet.link
似乎是一个开始,但它不能让我访问Greenlet
包含最终结果的内容(据我所知)。
我如何模仿Finagle
和操作?map
flatMap
gevent.Greenlet