Skip to content

Commit e057088

Browse files
committed
more testsg
1 parent 0470be3 commit e057088

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

test/sci/async_await_test.cljs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,16 +489,36 @@
489489
or-atom (atom 0)
490490
m (or (await (js/Promise.resolve :truthy))
491491
(do (swap! or-atom inc) :never))
492-
m-side-effects @or-atom]
492+
m-side-effects @or-atom
493+
;; async fn calling another async fn
494+
n (let [async-add (^:async fn [x y]
495+
(+ (await (js/Promise.resolve x))
496+
(await (js/Promise.resolve y))))
497+
async-mul (^:async fn [x y]
498+
(* (await (async-add x 1))
499+
(await (js/Promise.resolve y))))]
500+
(await (async-mul 2 3)))
501+
;; nested do blocks
502+
o (do
503+
(do
504+
(await (js/Promise.resolve :inner))
505+
(do
506+
(await (js/Promise.resolve :deeper))
507+
:nested-result)))
508+
;; for comprehension with await
509+
p (vec (for [x (await (js/Promise.resolve [1 2]))]
510+
(* x 2)))]
493511
{:a a :b b :c c :d d :e e :f f :g g :h h :i i :j j :k k
494512
:l l :l-side-effects l-side-effects
495-
:m m :m-side-effects m-side-effects}))
513+
:m m :m-side-effects m-side-effects
514+
:n n :o o :p p}))
496515
(test-complex)")]
497516
(p/let [result v]
498517
(is (= {:a 1 :b 7 :c 17 :d 3 :e 42 :f :matched-x :g 10 :h 11 :i 101
499518
:j :found :k 3
500519
:l false :l-side-effects 0
501-
:m :truthy :m-side-effects 0} result))))
520+
:m :truthy :m-side-effects 0
521+
:n 9 :o :nested-result :p [2 4]} result))))
502522
(p/catch (fn [err]
503523
(is false (str err))))
504524
(p/finally done)))))

0 commit comments

Comments
 (0)