File tree Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change 1
1
### 0.2.0-SNAPSHOT
2
2
3
- Contributions by Matthew Davidson
3
+ Contributions by Matthew Davidson, Ryan Smith
4
4
5
- * Modernized indentation to match current Clojure styles and fixed misalignments
5
+ * Switch to ` bound-fn ` in ` let-flow ` to fix bug where dynamic vars were incorrect for other threads
6
+ * Modernized indentation to match current Clojure styles and fix misalignments
6
7
7
8
### 0.1.9
8
9
Original file line number Diff line number Diff line change 1330
1330
[gensym val])
1331
1331
[gensym
1332
1332
`(~chain-fn (~zip-fn ~@deps)
1333
- (fn [[~@(map gensym->var deps)]]
1333
+ (bound- fn [[~@(map gensym->var deps)]]
1334
1334
~val))])))
1335
1335
(range )
1336
1336
vars'
1337
1337
vals'
1338
1338
gensyms)]
1339
1339
(~chain-fn (onto (~zip-fn ~@body-dep?) executor#)
1340
- (fn [[~@(map gensym->var body-dep?)]]
1340
+ (bound- fn [[~@(map gensym->var body-dep?)]]
1341
1341
~@body)))))))
1342
1342
1343
1343
(defmacro let-flow
Original file line number Diff line number Diff line change 5
5
[manifold.utils :as utils]
6
6
[clojure.test :refer :all ]
7
7
[manifold.test-utils :refer :all ]
8
- [manifold.deferred :as d]))
8
+ [manifold.deferred :as d]
9
+ [manifold.executor :as ex]))
9
10
10
11
(defmacro future ' [& body]
11
12
`(d/future
72
73
(d/chain #(/ 1 %))
73
74
(d/catch ArithmeticException (constantly :foo ))))))
74
75
76
+ (def ^:dynamic *test-dynamic-var*)
77
+
75
78
(deftest test-let-flow
76
79
77
80
(let [flag (atom false )]
93
96
(d/let-flow [[x] (future' [1 ])]
94
97
(d/let-flow [[x'] (future' [(inc x)])
95
98
y (future' true )]
96
- (when y x')))))))
99
+ (when y x'))))))
100
+
101
+ (testing " let-flow callbacks happen on different executor retain thread bindings"
102
+ (let [d (d/deferred (ex/fixed-thread-executor 1 ))
103
+ test-internal-fn (fn [] (let [x *test-dynamic-var*]
104
+ (d/future (Thread/sleep 100 ) (d/success! d x))))]
105
+ (binding [*test-dynamic-var* " cat" ]
106
+ (test-internal-fn )
107
+ (is (= [" cat" " cat" " cat" ]
108
+ @(d/let-flow [a d
109
+ b (do a *test-dynamic-var*)]
110
+ [a b *test-dynamic-var*])))))))
97
111
98
112
(deftest test-chain-errors
99
113
(let [boom (fn [n] (throw (ex-info " " {:n n})))]
388
402
(Thread/sleep (rand-int 10 ))
389
403
(d/success! d 1 )
390
404
(is (= 1 @@result)))))
405
+
You can’t perform that action at this time.
0 commit comments