This is a simple node.js based program using core.async. The question is: Why does the program terminate, although there is this "while true" loop inside the go macro in main ?
(ns node-hello-world.core (:require-macros [cljs.core.async.macros :refer [go]]) (:require [cljs.core.async :as async :refer [>! <! put! chan alts!]] [cljs.nodejs :as node] [goog.events :as events] [goog.dom.classes :as classes]) (:import [goog.events EventType])) (def http (node/require "http")) (node/enable-util-print!) (def all-results (atom [])) (def ch (chan)) (defn callback [response index] (let [result (atom "")] (.setEncoding response "utf8") (.on response "data" (fn [data] (swap! result str data))) (.on response "end" (fn [] (put! ch {:index index :result (count @result)}))))) (defn load-single [payload] (.get http (:url payload) (fn [response] (callback response (:index payload))))) (defn load [urls] (let [payload (map-indexed (fn [idx url] {:index idx :url url}) urls)] (loop [p payload] (when (seq p) (do (load-single (first p)) (recur (rest p))))))) (defn display [all] (println (sort #(< (:index %1) (:index %2)) all))) (defn -main [& args] (go (while true (let [result (<! ch)] (swap! all-results conj result) (if (= (count @all-results) (count args)) (display @all-results) )))) (load args)) (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 clojurescript+unsubscr...@googlegroups.com. To post to this group, send email to clojurescript@googlegroups.com. Visit this group at http://groups.google.com/group/clojurescript.