(code->results forms cb)
(code->results forms cb {:keys [*current-ns *state custom-load timeout disable-timeout?], :or {*current-ns (atom (quote cljs.user)), *state *cljs-state, custom-load custom-load!, timeout 4000, disable-timeout? false}, :as opts})
Evaluates each form, providing the results in a callback.
If any of the forms are strings, it will read them first.
Source
(defn
code->results
"Evaluates each form, providing the results in a callback.\n If any of the forms are strings, it will read them first."
([forms cb] (code->results forms cb {}))
([forms
cb
{:keys [*current-ns *state custom-load timeout disable-timeout?],
:or
{*current-ns (atom 'cljs.user),
*state *cljs-state,
custom-load custom-load!,
timeout 4000,
disable-timeout? false},
:as opts}]
(let
[init-forms
(vec
(concat
['(ns cljs.user)]
(when-not
disable-timeout?
['(def ps-last-time (atom 0))
'(defn
ps-reset-timeout!
[]
(reset! ps-last-time (.getTime (js/Date.))))
'(defn
ps-check-for-timeout!
[timeout]
(when
(> (- (.getTime (js/Date.)) @ps-last-time) timeout)
(throw (js/Error. "Execution timed out."))))])
['(set! *print-err-fn* (fn [_])) (list 'ns @*current-ns)]))
timeout-cb
(fn
[results]
(eval-forms
(add-timeouts-if-necessary timeout forms results)
cb
*state
*current-ns
custom-load))
init-cb
(fn
[results]
(eval-forms
(if disable-timeout? forms (map wrap-macroexpand forms))
(if disable-timeout? cb timeout-cb)
*state
*current-ns
custom-load))]
(eval-forms init-forms init-cb *state *current-ns custom-load))))