I wonder why the following program terminates. (count answers) is always < 2. 
Therefore recur should jump back to the go-loop. But the program finishes. But 
why ? 

(ns crawler.core
  (:require-macros [cljs.core.async.macros :refer [go go-loop]])
  (:require [cljs.nodejs :as node]
            [cljs.core.async :as async :refer [>! <! put! chan alts!]]))

(node/enable-util-print!)

(def http
  (node/require "http"))

(defn load [ch url]
  (let [result (atom "")]
    (.get http url (fn [response]
                     (.setEncoding response "utf8")
                     (.on response "data" (fn [data] (swap! result str data)))
                     (.on response "end" (fn [] (put! ch {:url url :content 
@result})))))))

(def results (async/chan))

(go
  (load results "http://news.ycombinator.com/";))

(go
  (load results "http://nodejs.org";))

(defn -main [& args]
  (go-loop [answers []]
           (let [answer (<! results)]
             (println (count answers))
             (if (< (count answers) 2)
               (recur (conj answers answer))
               (doseq [a answers]
                 (println (:url a)))))))

(set! *main-cli-fn* -main)

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to