...
Last active
December 16, 2017 00:56
-
-
Save namoopsoo/fa903799b958ffc9f279cd293e83e9d9 to your computer and use it in GitHub Desktop.
more cloj notes
(comment
"basic callback"
(let [callback-fn #(+ 5 %)
]
(callback-fn 10))
)
- ...
user=> (let [callback-fn #(+ 5 %)
#_=> ]
#_=> (callback-fn 10))
15
(comment
"future w callback func"
(defn use-callback-when-done
[callback-fn]
(future (callback-fn (+ 4 5))))
(def output (use-callback-when-done #(println "printings.. " % " .end")))
)
- =>
user=> (def output (use-callback-when-done #(println "printings.. " % " .end")))
#'user/output
printings.. 9 .end
user=>
(comment
"use a go put onto a channel callback..."
(defn use-callback-when-done
[callback-fn]
(future (callback-fn (+ 4 5))))
(require
['clojure.core.async
:refer ['>! '<! '>!! '<!! 'go 'chan
'alts! 'alts!! 'timeout]])
(let [
my-results-chan (chan)
callback-fn #(go (>! my-results-chan %))
output (use-callback-when-done callback-fn)
]
; (fn [x] (<!! my-results-chan))
(println "looking at the channel: " (<!! my-results-chan))
(println "done..")
)
)
- ==>
user=> (let [
#_=> my-results-chan (chan)
#_=> callback-fn #(go (>! my-results-chan %))
#_=> output (use-callback-when-done callback-fn)
#_=> ]
#_=> ; (fn [x] (<!! my-results-chan))
#_=> (println "looking at the channel: " (<!! my-results-chan))
#_=> (println "done..")
#_=> )
looking at the channel: 9
done..
nil
user=>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tools.trace debugging exceptions and stack trace
[org.clojure/tools.trace "0.7.9"]
user=> (use 'clojure.tools.trace)