Skip to content

Instantly share code, notes, and snippets.

@namoopsoo
Last active December 16, 2017 00:56
Show Gist options
  • Save namoopsoo/fa903799b958ffc9f279cd293e83e9d9 to your computer and use it in GitHub Desktop.
Save namoopsoo/fa903799b958ffc9f279cd293e83e9d9 to your computer and use it in GitHub Desktop.
more cloj notes

basic callbacks...

(comment 
  "basic callback"
  (let [callback-fn #(+ 5 %)
        ]
    (callback-fn 10))
)
  • ...
user=>   (let [callback-fn #(+ 5 %)
  #_=>         ]
  #_=>     (callback-fn 10))
15

callback w future

(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=> 

callback and core async...

(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=>
@namoopsoo
Copy link
Author

tools.trace debugging exceptions and stack trace

user=> (use 'clojure.tools.trace)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment