3

我正在通过代理获取 url,其中每个代理的状态都是一个向量,其中包含代理主机和它从中获取的端口。

我试图返回获取的页面的内容,同时将代理的状态保持为包含主机和端口的向量。

这就是我到目前为止所拥有的。

(defn fetch-url-with-proxy [url]
  (letfn [(fetch-fn [host-port url]
            (let [[host port] host-port]
              (fetch-url url host port)
              host-port))]
    (send-off (agent-from-pool proxy-pool) fetch-fn url)))

不幸的是,我目前返回代理,而不是 fetch-url 的内容。

任何帮助,将不胜感激!

4

1 回答 1

3

使用 promise 等待结果:

(defn fetch-url-with-proxy [url]
  (letfn [(fetch-fn [host-port url result]
      (let [[host port] host-port]
        (deliver result (fetch-url url host port))
          host-port))]
  (let [result (promise)]
    (send-off (agent-from-pool proxy-pool) fetch-fn url result)
    @result)))
于 2012-06-23T16:30:56.403 回答