Skip to content

Commit 47c733e

Browse files
committed
workz
1 parent 854ea19 commit 47c733e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/sci/async.cljs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns sci.async
22
(:require
33
[sci.core :as sci]
4+
[sci.ctx-store :as store]
45
[sci.impl.copy-vars]
56
[sci.impl.load :as load]
67
[sci.impl.namespaces]
@@ -205,13 +206,18 @@
205206
[promise]
206207
(.-__sci_await ^js promise))
207208

208-
(defn- require* [ctx & libspecs]
209-
(let [ctx (assoc ctx :last-ns (or (:last-ns ctx)
209+
(defn- require* [?ctx & libspecs]
210+
(let [ctx* (when (map? ?ctx)
211+
?ctx)
212+
ctx (or ctx* (store/get-ctx))
213+
libspecs (if ctx* libspecs
214+
(cons ?ctx libspecs))
215+
ctx (assoc ctx :last-ns (or (:last-ns ctx)
210216
(volatile! @sci/ns)))
211217
p (handle-libspecs ctx libspecs)]
212218
(await p)))
213219

214220
(def require
215221
"Async require that can be substituted for sync require by
216222
`{:namespaces {'clojure.core {'require scia/require}}}`"
217-
(sci.impl.copy-vars/new-var 'require require* true))
223+
(sci.impl.copy-vars/new-var 'require require*))

test/sci/async_test.cljs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
_ (is (= "user" res))
5050
code "(require '[foobar2 :as foo]) (foo/hello)"
5151
res (scia/eval-string* ctx code)
52+
_ (prn :after)
5253
_ (is (= :bye res))]
5354
(done))))
5455

0 commit comments

Comments
 (0)