Skip to content

Instantly share code, notes, and snippets.

@skrat
Forked from anonymous/.cljs
Last active June 8, 2017 10:01
Show Gist options
  • Save skrat/ef08d7e3c2914f9a9d2d2636c3c6ffcc to your computer and use it in GitHub Desktop.
Save skrat/ef08d7e3c2914f9a9d2d2636c3c6ffcc to your computer and use it in GitHub Desktop.
(defn api-call-with-cb [api-call cb]
(go (let [resp (<! (api-call))]
(if (= 200 (:status resp))
[(:body resp) nil]
[nil resp]))))
(defn api-fetch
([api-call cb] (api-call-with-cb api-call cb))
([api-call] (api-call-without-cb api-call)))
(defn make-callback [item]
(fn [aux]
(prn "Item in this fn" item)
(reset! rez aux)))
(go
(prn "Items " @items) ;; prints items collection with data in it
(doseq [item @items]
(prn "this is t " item) ;; prints a map (one item of @items collection)
(<! (api-fetch #(get-stuff (:_id item)) ;; chrome dev tools show the request made with :_id param read correctly
(make-callback item)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment