core.async - Clojurescript - Uncaught Error: <! used not in (go ...) block -


i in clojurescript, , trying use core.async result native javascript function (i in browser), , conditionally integrate map.

i have function wrap native browser call (inspired timothy baldridge's talk on core.async, approx. 34 min interested) :

(defn geolocation []     (let [c (chan)          cb (fn [e] (put! c (js->clj e)))]      (if (exists? js/navigator.geolocation)        (.getcurrentposition js/navigator.geolocation. cb cb)        (put! c {:error "geolocation not supported"}))      c)) 

i can use :

   ;; works    (go (.log js/console "res1 -"  (<! (geolocation))))     ;; (not sure how print though)    (go (println "res2 - "  (-> {}                             (assoc :test (<! (geolocation))))))     ;; fails... why ?    (go (println "res3 - "  (-> {}                                (#(when true                                    (assoc % :test (<! (geolocation)))))))) 

the last example fails error : uncaught error: <! used not in (go ...) block, though thought using same kind of structure.

what doing wrong ?

note : requiring :require-macro directive, like described here.

the go macro take body it's given , transform <! , alt! , >! calls state machine. won't walk functions:

couldn't use loop in go block of core.async?

by stops translation @ function boundaries, mean this: go block takes body , translates state-machine. each call <! >! or alts! (and few others) considered state machine transitions execution of block can pause. @ each of points machine turned callback , attached channel. when macro reaches fn form stops translating. can make calls <! inside go block, not inside function inside code block.

this part of magic of core.async. without go macro, core.async code lot callback-hell in other langauges.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -