Skip to content

Instantly share code, notes, and snippets.

@geraldodev
geraldodev / promises-cljs.md
Created August 16, 2022 09:39 — forked from pesterhazy/promises-cljs.md
Promises in ClojureScript

Chaining promises

Chaining promises in ClojureScript is best done using the thread-first macro, ->. Here's an example of using the fetch API:

(-> (js/fetch "/data")
    (.then (fn [r]
             (when-not (.-ok r)
               (throw (js/Error. "Could not fetch /data")))
             (.json r)))