Skip to content

Instantly share code, notes, and snippets.

@mfikes
Created November 16, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfikes/e8c48b177170ccde7a6a to your computer and use it in GitHub Desktop.
Save mfikes/e8c48b177170ccde7a6a to your computer and use it in GitHub Desktop.
avoid compiler atom contention
(defn compile-task [^LinkedBlockingDeque deque input-set compiled opts failed]
(loop [ns-info (.pollFirst deque)]
(when (and ns-info (not @failed))
(let [{:keys [requires]} ns-info
input-set' @input-set]
(if (every? #(not (contains? input-set' %)) requires)
(do
(try
(let [orig env/*compiler*]
(binding [env/*compiler* (atom @env/*compiler*)]
(swap! compiled conj
(-compile (or (:source-file ns-info)
(:source-forms ns-info))
; - ns-info -> ns -> cljs file relpath -> js relpath
(merge opts
{:output-file (comp/rename-to-js
(util/ns->relpath (:ns ns-info)))})))
(reset! orig @env/*compiler*)))
(catch Throwable e
(util/debug-prn e)
(reset! failed true)))
(when-not @failed
(when-let [ns (:ns ns-info)]
(swap! input-set disj ns))
(recur (.pollFirst deque))))
(do
(Thread/sleep 10)
(recur ns-info)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment