Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Blocking Deref Blog example
(defn blocking-deref
"Given an atom and a Result object, attempt to cycle the process tick on derefing until `pred-fn` isn't true
By default, `pred-fn` is nil?
Once the condition doesn't hold, the Result will be set to @a, and @a is returned"
([a r]
(blocking-deref a r nil?))
([a r pred-fn]
(if (pred-fn @a)
(node/process.nextTick #(blocking-deref a r pred-fn))
(do (.setValue r @a)
;; This is the direct Result object you can use to access
;; a git config map
(def git-config-res
(let [res (goog.result.SimpleResult.)]
(git-config-atom "")
(git-config-atom "")
((fn [a] (blocking-deref a res #(< (count %) 2)))))
(defn git-config-atom
"Call the `git config` command to grab the value of a given key.
Return an atom that will hold the return/output string in a map {k output-value}.
Optionally pass in an atom (allowing you to build up many returns)"
(git-config-atom k (atom {})))
([k ret]
(do (sys-exec (str "git config --get " (name k))
(fn [_ out _]
(swap! ret assoc (keyword k) (cstr/trim out))))
(defn -main [& args]
(let [git-root core/git-root-res
git-conf core/git-config-res]
(result/wait git-root
#(binding [core/*repo-root* (.getValue git-root)]
(result/wait git-conf
(fn [] (main-control git-conf args)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.