Skip to content

Commit dae3ea9

Browse files
committed
ASYNC-270: Modified the operation of futurize to account for the change to Executor interface in ASYNC-272. The futurize function now creates and returns future. Also, merging in options so that exeception is not thrown when :exec not supplied.
1 parent f644f96 commit dae3ea9

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/main/clojure/clojure/core/async/flow/impl.clj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
(fn [& args]
3131
(let [^Executor e (if (instance? Executor exec)
3232
exec
33-
(disp/executor-for exec))]
34-
(.execute e ^Runnable #(apply f args)))))
33+
(disp/executor-for exec))
34+
fut (java.util.concurrent.CompletableFuture.)]
35+
(.execute e ^Runnable #(.complete fut (apply f args)))
36+
fut)))
3537

3638
(defn prep-proc [ret pid {:keys [proc, args, chan-opts] :or {chan-opts {}}}]
3739
(let [{:keys [ins outs signal-select]} (spi/describe proc)

src/test/clojure/clojure/core/async/flow_test.clj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212

1313
(deftest test-futurize
1414
(testing ""
15-
(let [es (reify java.util.concurrent.ExecutorService
16-
(^java.util.concurrent.Future submit [_ ^Callable f]
17-
(future-call (comp vector f))))]
15+
(let [in-es? (atom false)
16+
es (reify java.util.concurrent.Executor
17+
(^void execute [_ ^Runnable f]
18+
(reset! in-es? true)
19+
(future-call f)))]
1820
(is (= 16 @((flow/futurize #(* % %) {:exec :mixed}) 4)))
1921
(is (= 16 @((flow/futurize #(* % %)) 4)))
20-
(is (= [16] @((flow/futurize #(* % %) {:exec es}) 4))))))
22+
(is (= 16 @((flow/futurize #(* % %) {:exec es}) 4)))
23+
(is @in-es?))))
2124

0 commit comments

Comments
 (0)