Skip to content

Instantly share code, notes, and snippets.

Created December 15, 2012 21:02
Show Gist options
  • Select an option

  • Save anonymous/4299179 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/4299179 to your computer and use it in GitHub Desktop.
(defn ^::blocking get-url
[{:keys [^BlockingQueue queue] :as state}]
(let [url (as-url (.take queue))]
(try
(if (@crawled-urls url)
state
{:url url
:content (slurp url)
::t #'process})
(catch Exception e
state)
(finally (run *agent*)))))
(defn run
([] (doseq [a agents] (run a)))
([a]
(when (agents a)
(send a (fn [{transition ::t :as state}]
(when-not (paused? *agent*)
(let [dispatch-fn (if (-> transition meta ::blocking)
send-off
send)]
(dispatch-fn *agent* transition)))
state)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment