Comment made by: wxlite
Seems and works abnormal in many cases, not just with <!.
I tested this in:
clojure-1.8.0, clojurescript-1.7.228, core.async-0.2.374.
this test need nodejs with the request module.
(def request (js/require "request"))
Now I try to send request to an unaccessible site: google.
Yes, I can't use google.
`
(def result-chan (chan))
(request
"http://www.google.com"
(fn [err res body]
(go
(if (and (not err) (= (.-statusCode res) 200))
(>! result-chan body)
(>! result-chan [])))))
`
the result should be "(link: )" (the request will timeout make "err" non-nil)
(go
(println "result:" (<! result-chan)))
but actually I get:
1. _TypeError: Cannot read property 'statusCode' of undefined ..._ {color}
I have printed err and I am sure it's a JS object in this case, not nil or false. that's why res is undefined.
And it also means the short-circuit for and didn't work.
to make things right, use "if" instead of "and"
`
(def result-chan (chan))
(request
"http://www.google.com"
(fn [err res body]
(go
(if (not err)
(if (= (.-statusCode res) 200)
(>! result-chan body)
(>! result-chan []))
(>! result-chan [])))))
`
then test it again:
(go
(println "result:" (<! result-chan)))
work as expected now:
result: []