Skip to content

Instantly share code, notes, and snippets.

@tristanstraub
Created January 21, 2017 21:04
Show Gist options
  • Save tristanstraub/20586c6a5dad5cf7504f6c2f54b59186 to your computer and use it in GitHub Desktop.
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.
(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