Skip to content

Instantly share code, notes, and snippets.

@tristanstraub
Created January 21, 2017 21:06
Show Gist options
  • Save tristanstraub/e49d3453bbf9168e70fcb592454cf436 to your computer and use it in GitHub Desktop.
Save tristanstraub/e49d3453bbf9168e70fcb592454cf436 to your computer and use it in GitHub Desktop.
In clojure, call a function returning a promise and convert it to a channel
(defn- <promise
"Call a function that returns a promise and convert it into a channel"
[f & args]
(let [out (a/chan)
done (fn [& _] (a/close! out))]
(.then (apply f args) done done)
out))
(a/<!! (<promise (fn [& args] (apply promise-style-f args)))
(a/<!! (<promise promise-style-f 1 2 3)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment