Created
January 21, 2017 21:04
-
-
Save tristanstraub/20586c6a5dad5cf7504f6c2f54b59186 to your computer and use it in GitHub Desktop.
In clojure, call continuation passing style function and return a channel with result.
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- <cb | |
"Call an callback style function and return a channel containing the result of calling the callback" | |
[f & args] | |
(let [out (a/chan)] | |
(apply f (conj (into [] args) (fn [& args] | |
(a/put! out args) | |
(a/close! out)))) | |
out)) | |
(a/<!! (<cb (fn [cb] (cb-style-f 1 2 3 cb)))) | |
(a/<!! (<cb cb-style-f 1 2 3)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment