Created
January 21, 2017 21:06
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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