Skip to content

Commit

Permalink
make let-flow wait on all bound values, fix #118
Browse files Browse the repository at this point in the history
  • Loading branch information
ztellman committed May 17, 2018
1 parent 193f5f4 commit 651594c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/manifold/deferred.clj
Expand Up @@ -1306,12 +1306,14 @@
(back-references marker form)))
(range))))
binding-dep? (->> gensym->deps vals (apply concat) set)

body-dep? (->> `(let [~@(interleave
vars'
(repeat nil))]
~@body)
(back-references marker)
(map (zipmap vars' gensyms))
(concat (drop (count vars) gensyms))
set)
dep? (set/union binding-dep? body-dep?)]
`(let [executor# (manifold.executor/executor)]
Expand Down
9 changes: 9 additions & 0 deletions test/manifold/deferred_test.clj
Expand Up @@ -73,6 +73,15 @@
(d/catch ArithmeticException (constantly :foo))))))

(deftest test-let-flow

(let [flag (atom false)]
@(let [z (clojure.core/future 1)]
(d/let-flow [x (d/future (clojure.core/future z))
_ (d/future (Thread/sleep 1000) (reset! flag true))
y (d/future (+ z x))]
(d/future (+ x x y z))))
(is (= true @flag)))

(is (= 5
@(let [z (clojure.core/future 1)]
(d/let-flow [x (d/future (clojure.core/future z))
Expand Down

0 comments on commit 651594c

Please sign in to comment.