...
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=>
atom vec []
and while loop...
(let [results-atom (atom [])]
;
; (println "elements: " (count @results-atom))
; (swap! results-atom conj "hi")
;results-atom
(while
(< (count @results-atom) 3)
(do
(println "doing")
; insert
(swap! results-atom conj "hi")
(println "elements: " (count @results-atom))
))
; done
(println "Done. Now have elements: " (count @results-atom))
)
- =>
doing
elements: 1
doing
elements: 2
doing
elements: 3
Done. Now have elements: 3
nil
tools.trace debugging exceptions and stack trace
- https://github.com/clojure/tools.trace
- dependency:
[org.clojure/tools.trace "0.7.9"]
user=> (use 'clojure.tools.trace)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
test
http-kit
timeout..timeout 1ms
..Answer the question: does
http-kit
func use the callback if there is an{:error ...}
?