Hi, I'm not sure if I can rewrite the following piece of JavaScript targeting 
node:

var loadUrl = function(url, success, error) {
  http.get(url, function(res) {
    var buffer = '';
    res.on('data', function(chunk) {
      buffer += chunk;
    });
    res.on('end', function() {
      success(buffer);
    });
  }).on('error', function(e) {
    error(e);
  });
};

to this:

(defn load-url-async
  [url success error]
  (let [loader (.get http url (fn [res]
                                (let [buffer (atom "")]
                                  (.on res "data" #(swap! buffer str %))
                                  (.on res "end" #(success @buffer)))]
    (.on loader "error" error))

Can someone experienced confirm that I can use atom inside the function?

Thanks

-- 
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